统计问题 (100分)

Z

zhj218

Unregistered / Unconfirmed
GUEST, unregistred user!
如:
字段 No.1 creatTime completeTime
数据:
a 2002-2-14
a 2002-2-13 2002-2-14
b 2002-2-14
c 2002-2-14
b 2002-2-14
如何用sql找出creatTime和completeTime 2002-2-14实现以下结果:
字段 No.1 No.2 No.3
数据:
a 1 1
b 1 1
c 1

No.2 No.3 是统计记录中有值的个数
 
select no1,count(no2) as no2,count(no3) as no3 from table group by no1
 
SELECT no1, CASE COUNT(no2) WHEN 0 THEN NULL ELSE COUNT(no2) END NO2,
CASE COUNT(no3) WHEN 0 THEN NULL ELSE COUNT(no3) END No3
FROM temptable
GROUP BY no1
 
对不起,是我的问题错了,应该是修改以后的内容
 
select no.1,sum(case when createtime=:rq then 1 else null end),
sum(case when completetime=:rq then 1 else null end)
from tablename
group by no.1
 
多人接受答案了。
 
顶部