当前位置: 代码迷 >> Sql Server >> 急求一复杂语句,该怎么处理
  详细解决方案

急求一复杂语句,该怎么处理

热度:29   发布时间:2016-04-27 21:12:27.0
急求一复杂语句
表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
  相关解决方案