SELECT COUNT(*),updateTime FROM Table 
GROUP BY 
YEAR(updateTime)
sql 正常。但
SELECT COUNT(id),o.updateTime FROM Table o
GROUP BY 
YEAR(o.updateTime)貌似Group by 之后的year不支持。去掉year 单独o.updateTime可以。
我的意图就是如上sql,查询每年成交量 ,请问hibernate里面怎么搞?有什么解决方法!

解决方案 »

  1.   

    YEAR(updateTime)把这个updateTime改为数据库表对应的字段名。
      

  2.   


    还是不行。有人貌似提出过这个问题。http://www.cnblogs.com/a-peng/archive/2010/02/06/1665042.htmlGROUP BY之后不能加函数.  
    YEAR(o.updateTime)
     但貌似没有解决方法。
      

  3.   

    貌似hibernate里面查询实体
    你试试这样做可不可以:
    from tableEntity group by to_char('yyyy')
      

  4.   


    数据库 Mysql
    使用hibernate 数据表table
    id  updateTime
    1    2010-09-09
    2    2010-09-09
    3    2010-10-01
    ....
      

  5.   

    使用的MYSQL数据库吧,把YEAR改成year看看
      

  6.   

    哦。我搞错了。可以的SELECT COUNT(id),o.updateTime FROM Table o
    GROUP BY  
    YEAR(o.updateTime)
    以上没问题。问题出在QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 27 [select count(DISTINCT year(o.updateTime)) from com.xxx.bean.Price o]
    select count(DISTINCT year(o.updateTime)) from com.xxx.bean.Price o
    这句出了问题。select count(DISTINCT o.updateTime) from com.xxx.bean.Price o 这样没问题。
    莫非count distinct里面不能在家year?
     
      

  7.   

    java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 27 [select count(DISTINCT year(o.updateTime)) from com.xxxx.bean.Price o]
    晕倒。这句提示少了 (   貌似没有却少哇。谁帮我看看
      

  8.   

    SELECT COUNT(DISTINCT YEAR(o.updateTime)) FROM Price osql内直接查询没问题。  但hibernate 通不过