日期:2014-05-19  浏览次数:20478 次

急求一复杂语句
表a
ID       Time
1         2006.1.1
1         2006.2.1
2         2006.1.1

计算出每个月每一天的不同ID记录总数。




------解决方案--------------------
select convert(varchar(10),Time,120),count(ID)
from (select distinct ID,Time from 表a) a
group by convert(varchar(10),Time,120)
------解决方案--------------------
Select
Count(Distinct ID) As 总数,
[Time]
From
a
Group By
[Time]
------解决方案--------------------
--试试

select distinct time,(select count(*) from (select distinct id from a aa where aa.time =a.time)t)
from a

------解决方案--------------------
select count(distinct id) 总数,Time 时间
from a
group by Time
------解决方案--------------------
SELECT COUNT(id) AS Expr1, dt, id
FROM td
GROUP BY dt, id