日期:2014-05-18  浏览次数:20521 次

求高手指教这句sql的写法
我的表里面有一个id和一个时间(YYYYmmdd)字段,是多对多关系,一个id对应多个时间,一个时间也有多个id,我的问题是想写一个查询是:查询出1天内id出现次数超过100次的id,我想到好几个小时了都搞不定,我写的是:
SQL code

select time,id
FROM table
GROUP BY time,id
HAVING count(tmp.lid)>200;



结果查出来是空的,希望高手们指教指教,谢谢

------解决方案--------------------
SQL code
--总记录>100,查看对应的每天记录
select 
    a.ID,a.[time],COUNT(*) as 每天记录
from (select ID from table1 group by ID having COUNT([time])>100) as a
inner join table1 as b on a.ID=b.ID
group by a.ID,a.[time]

------解决方案--------------------
是查某天某个ID超过了100次?
SQL code
select id , convert(varchar(10),time,120) time 
from table1
group by id , convert(varchar(10),time,120)
having count(1) > 100