Sql 在HQL中使用子查询

Sql 在HQL中使用子查询,sql,hibernate,subquery,hql,Sql,Hibernate,Subquery,Hql,我有以下SQL查询,我需要从中删除有效的HQL查询 Select Temp.*, (select case when count(tab7.id)>0 then 1 else 0 end from table7 tab7 where tab7.id = Temp.col_3_0_ ) As Col_6_0_ from (

我有以下SQL查询,我需要从中删除有效的HQL查询

  Select   Temp.*,
    (select
       case 
        when count(tab7.id)>0 then 1 
        else 0 
       end 
      from
       table7 tab7 
      where
       tab7.id = Temp.col_3_0_ 
       ) As Col_6_0_  
       from (Select
      tab5.col1 As Col_0_0_,
      tab5.col2 As Col_1_0_,
      sum(tab5.col3) as col_2_0_,
      tab5.col4 as col_3_0_,
     from

      table5 tab5,
       table1 tab1
  table2 tab2
  where
    tab2.somecol=tab5.somecol 
      and tab1.id=tab5.id 
     GROUP BY  tab5.col1    ,
      tab5.col2                 ,
       tab5.col4   ) Temp
但是,当我试图以这种方式执行HQL查询时,我面临着语法问题

问题:

  • 有没有办法在HQL中使用
    from
    cluase中的子查询

  • 如果没有,我如何在hibernate中实现这一点


  • 请提供帮助。

    您可以在hibernate中使用分离的条件来启动子查询或查询中的条件

    下面是您的示例代码

    Criteria cr=getSession().createCriteria(Payment.class,“p”);
    cr.add(subquerys.propertyNotIn(“P.paymentId”,DetachedCriteria.forClass(return.class,“return”)
    .add(限制)或(限制eq(“退款已取消”,错误),
    限制。isNull(“return.isCancelled”))
    .setProjection(Property.forName(“return.payment.paymentId”))


    干杯

    以及如何在此处形成
    分组依据
    ,包括内部子查询列(
    tab5.col3
    )的总和,如果内部查询中有sum,则没有GROUP BY的含义