++++++++++++++++++
要求:
1、表中有4条重复数据(1~4 对应 10~13),现在只对10、11进行去重,12、13保留。展示去重以后的数据。
++++++++++++++
求代码,谢谢
为什么10、11去重,12、13保留,规则是什么。
为什么要去掉10、11,保留1、2
不同的规则有不同的写法
比如说取出每个名字里age最大的
select a.name, a.age, a.grade from table a where not exists (select age, name from table b where b.age > a.age and b.name = a.name)
或者每个名字里id最小的
select a.name, a.id, a.grade from table a where not exists (select id, name from table b where b.id < a.id and b.name = a.name)
对于特殊的再加上
select a.id,a.name, a.age, a.grade from table a where not exists (select id, name from table b where b.id < a.id and b.name = a.name)
union (select id, name, age, grade from table where id in (12, 13))