select b.name,
(case when pcamnt+noteamnt+serveramnt is null then 0 else pcamnt+noteamnt+serveramnt end ) as totolamnt,
(case when a.pcnum is null then 0 else a.pcnum end) pcnum,
(case when a.pcamnt is null then 0 else a.pcamnt end) pcamnt, 
(case when a.notenum is null then 0 else a.notenum end) notenum,
(case when a.noteamnt is null then 0 else a.noteamnt end) noteamnt,
(case when a.servernum is null then 0 else a.servernum end) servernum,
(case when a.serveramnt is null then 0 else a.serveramnt end) serveramnt 
from
(
select c.name as name,
sum(case when g.goodtype='A03020101' then g.number else 0 end) as pcnum,
sum(case when g.goodtype='A03020101' then g.budget else 0 end) as pcamnt, 
sum(case when g.goodtype='A03020102' then g.number else 0 end) as notenum,
sum(case when g.goodtype='A03020102' then g.budget else 0 end) as noteamnt, 
sum(case when g.goodtype='A03020103' then g.number else 0 end) as servernum,
sum(case when g.goodtype='A03020103' then g.budget else 0 end) as serveramnt 
from goods as g,computer as c 
where g.carcomputer is not null and g.carcomputer=c.id group by c.name
) as a full join (select name as name from computer) as b on a.name=b.name 类似这样复杂的查询,我怎么转换成 HQL Or Criteria?求教大虾了.

解决方案 »

  1.   

    真的太复杂的SQL,直接用存储过程或者createSQLQuery算了吧...
      

  2.   

    case   when 不是每种数据库都支持这样相同的语法,所以用楼上的createSQLQuery吧,使用原生SQL语句。不用HQL
      

  3.   

    谢谢各位,我也知道用hql不是很方便,不过createSqlQuery怎么用啊?好象要addEntity,我里面有查询结果的嵌套,不知道怎么用,希望大家帮帮我