在sql中使用带有count的case

时间:2013-09-11 06:49:39

标签: sql-server tsql count subquery case

我想从以下query.i尝试对命中计数进行分类,但它给了我错误。有人可以帮忙吗?

select case when (a.hit between 0 and 5) then 0
        when (a.hit between 6 and 10) then 1
        else 2,

    from    

    (select 
    distinct u.USER_NAME,
     r.VIEW_TYPE,
    B.ORG,

    g.CLUSTER
    ,Count(*) As HIT 
    from 
    dbo.Parameter p,
    dbo.Report r,
    dbo.User u,
    dbo.TimeStamp t,
    dbo.UserLog f,
    dbo.APP_USER B,
    (
        select CLUSTER,COUNTRY
from [dbo].[GEO]
union
select distinct CLUSTER,CLUSTER
from [dbo].[GEO]
    ) G
        where 
    p.PARAM_ID=f.PARAM_ID
    and r.REPORT_CUBE_ID=f.REPORT_ID
    and u.USER_NAME=f.USER_ID
    and r.VIEW_TYPE=f.ViewType
    AND T.TIME_STAMP_ID=F.[TIME STAMP_ID]
    AND u.EMAIL = B.EMAIL
    AND u.USER_NAME=B.USER_ID
    and p.GEO = G.COUNTRY
    and r.VIEW_TYPE='Industry View'

  group by CLUSTER,USER_NAME,VIEW_TYPE,b.ORG
  order by CLUSTER,USER_NAME,VIEW_TYPE,b.ORG) a

1 个答案:

答案 0 :(得分:1)

让我猜一下:

select case when (a.hit between 0 and 5) then 0
        when (a.hit between 6 and 10) then 1
        else 2
        END
from......

拉​​吉