表如下
id type
1 0
2 1
3 0
4 4
5 0
6 4我想要列出所有type=0的项目,如果type>0那么列出消重后的,出来的结果如下id type
1 0
2 1
3 0
4 4
5 0
删掉了id=6,type=4,,因为type=4的有id=4.消去重复的求哪位大哥可以写一条sql啊,不用union all可以嘛?
id type
1 0
2 1
3 0
4 4
5 0
6 4我想要列出所有type=0的项目,如果type>0那么列出消重后的,出来的结果如下id type
1 0
2 1
3 0
4 4
5 0
删掉了id=6,type=4,,因为type=4的有id=4.消去重复的求哪位大哥可以写一条sql啊,不用union all可以嘛?
select * from table group by type.
不过type=0的就不要消去了这可以设置条件嘛?
from 你的表
group by type, if(type = 0, id, -1)
order by id
(select max(id) id,type,count(type) cnt from test20 where type>0 group by type having cnt>1) b
on a.id=b.id where b.id is null