select sum(case when CheckStatus = 4 then 1 else 0 end ) from BasTimecard bt 没错
select bt.EmployeeName from asTimecard bt group by bt.EmployeeName 也没错select bt.EmployeeName ,sum(case when CheckStatus = 4 then 1 else 0 end ) from BasTimecard bt group by bt.EmployeeName  就报错了。。请问该怎么写
sum里面的CheckStatus改成bt.CheckStatus也是错。

解决方案 »

  1.   

    很奇怪
    select  bt.EmployeeName,sum( Case when  bt.CheckStatus = 4 then 1 else 0 end )  from BasTimecard bt  group by bt.EmployeeName
    就报
    "Could not execute query"
    {"ORA-00907: 缺失右括号"}
      

  2.   

    是不是该bt.CheckStatus == 4
    ?不太懂
      

  3.   

     BasTimecard ,asTimecard是同一个表么?
      

  4.   

    select bt.EmployeeName ,sum(case when CheckStatus = 4 then 1 else 0 end ) from BasTimecard bt group by 
    ----------
    其中的EmployeeName ,sum中间是中文输入状态的逗号.
    ----------
    BasTimecard bt
    asTimecard bt
    这不是2个表么?
    ---------------
    如果排除以上2个,这个sql肯定没有问题。
      

  5.   

    不要执行hql 改成执行sql
    再不不行就外面加一个 select * from (select  bt.EmployeeName,sum( Case when  bt.CheckStatus = 4 then 1 else 0 end )  from BasTimecard bt  group by bt.EmployeeName )
      

  6.   

    如果是hql
    那么注意属性的大小写
    试试select bt.employeeName ,sum(case when bt.checkStatus = 4 then 1 else 0 end ) from BasTimecard bt group by bt.employeeName
      

  7.   

    是同一个表。上面是打少了个B问题解决了。直接用CreateSQLQuery()跑就可以跑过去了。。
    不过还是觉得奇怪,用CreateQuery 的时候为什么上面两个查询分开就可以执行,拼到一起就出问题了。。