having

今天下午做一个分组统计查询,

select count(caseid) as nm,ar.AreaName,p.ProjectName,sp.codename as Purpose from dat_case c inner join DAT_Project p
on c.Projectid=p.Projectid  left join SYS_Area ar on ar.AreaId=P.AreaId  inner join sys_code sp on c.PurposeCode=sp.code
where CaseDate between '2011-05-23' and '2011-5-23' and FXTCompanyId=24 and c.cityid=6

先是NM放where 识别不了,那好用 count(caseid)放进去,,报错。

where后面不是放max count 之类的函数,

修改好的SQL:

select count(caseid) as nm,ar.AreaName,p.ProjectName,sp.codename as Purpose from dat_case c inner join DAT_Project p 
on c.Projectid=p.Projectid  left join SYS_Area ar on ar.AreaId=P.AreaId  inner join sys_code sp on c.PurposeCode=sp.code
where CaseDate between '2011-05-23' and '2011-5-23' and FXTCompanyId=24 and c.cityid=6
group by c.Projectid,ar.AreaName,p.ProjectName,sp.codename
having  count(caseid)between 1 and 10
posted @ 2011-05-23 17:30  lice  阅读(285)  评论(0编辑  收藏  举报