【问题标题】:using case with count in sql在sql中使用带计数的案例
【发布时间】:2013-09-15 01:56:24
【问题描述】:

我想对以下查询中的命中计数进行分类。我已经尝试过,但它给了我错误。有人可以帮忙吗?

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

【问题讨论】:

  • 你真的读过错误是什么吗?

标签: sql-server tsql count subquery case


【解决方案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......

拉吉

【讨论】:

  • 是的,我读过它。这是语法错误。我找不到语法问题。 :( 傻我。
  • @shishir_bindu 如果这确实是语法错误,您能否将答案标记为已接受?也不介意点赞:)
猜你喜欢
  • 1970-01-01
  • 2014-10-17
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多