比如:
id
0
0
0
1
1
1
2
2
查询的效果为:
id
0
0
0
1
2
也就是说对不为0的字段进行分组或者去除重复,怎么做到以上的效果呢?
sql..
sql 去除重复问题(分组问题)
答案:4 悬赏:0
解决时间 2021-03-15 00:45
- 提问者网友:相思瘸子
- 2021-03-14 12:31
最佳答案
- 二级知识专家网友:厌今念往
- 2021-03-14 13:46
试试:select A.id from (select id from table where id=0) A join (select id from table where id<>0 group by id) B onA.id=B.id
全部回答
- 1楼网友:怪咖小青年
- 2021-03-14 15:59
这种效果看你要如何去判断,可能需要Union
- 2楼网友:虚伪的现实
- 2021-03-14 15:33
select id from a where id = 0 union allselect distinct id from a where id <> 0
- 3楼网友:转身→时光静好
- 2021-03-14 14:59
忘了sqlserver 能不能用case when 了 ,oracle 用nvl 和casewhen 都可
select flag,(case when count(0) is null then 0 end) as num from table1 group by flag
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯