sql count 去重(sql语句求解COUNT (CASE WHEN THEN***)排除重复项)

本文目录
sql语句求解COUNT (CASE WHEN THEN***)排除重复项
select sum(case when A.CLOSE_ID=’T’ then 1 else 0 end)
from (select distinct A.CLOSE_ID,A.MO_NO from A) T
’完成种数’=COUNT(CASE WHEN A.CLOSE_ID=’T’ THEN A.MO_NO ELSE 0 END)这句的逻辑就有问题,你要求A.CLOSE_ID=’T’ 时, A.MO_NO 的个数吗?那样你直接写
select count(A.MO_NO) from A where A.CLOSE_ID=’T’ 就好了
就算你一定要用case when...then,你也要用sum而不是count,你用count是所以(CASE WHEN A.CLOSE_ID=’T’ THEN A.MO_NO ELSE 0 END)的个数,就算是0,它也是个值,仍然会被count进去啊,你只有sum时,0才是不会起做用的数。
SQL Server如何利用count(*)统计一张去掉重复记录的总行数
Select count(*)from [table] where id in (select distinct max(id) from [table] where gsmc like ’%碳资产%’ group by stockcode)
在第二条查询Max(id)的语句中增加distinct查询出的id记录都是唯一,没有重复记录。

更多文章:
dropdownlist 绑定(DropDownList 绑定所有项 并 显示指定项)
2026年10月11日 08:50
易语言网页api接口怎么调用(易语言,怎么读取网页json的api)
2026年10月11日 08:00
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40
another time(another time和other time的区别)
2026年10月11日 05:00






