例如有个表是  aid   num   createtime在HQL里 如何表达select *,(select sum(num) from tb where aid = t.aid and createtime<t.createtime) as csum 
from tb t
若实体也是  tb

解决方案 »

  1.   

    另外在HQL写法里 SQL的 convert 函数是否适用!!!
      

  2.   

    select t.*,sum(t.num)from tb t inner join tb t1 on t1.id  group by 主键ID主键ID 也可以换成其他字段,只要该字段在表里面的值唯一就可以了
      

  3.   

    select t.*,sum(t.num)from tb t inner join tb t1 on t.aid=t1.aid group by 主键ID
      

  4.   

    没有主键ID的话就这样写
    select t.*,sum(t.num)from tb t inner join tb t1 on t.aid=t1.aid and t.createtime<t1.createtime group by aid, num, createtime