微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用标准构建器为内部连接编写子查询并读取多选中的计数

如何解决如何使用标准构建器为内部连接编写子查询并读取多选中的计数

下面是相应的 MysqL 查询及其工作查询

  select tab4.id,tab4.name,tab7.city,tab7.state,tab7.phone,tab5.status_priority,tab5.model,tab5.code,tab5.number,tab5.ds_formatted_timestamp
  group_concat( distinct tab6.position),coalesce(b.counts,0) as count
  from table1 tab1
  inner join table2 tab2 on tab1.organization_id=tab2.organization_id
  inner join table3 tab3 on tab2.organization_id=tab3.organization_id
  inner join table4 tab4 on tab3.site_id=tab4.site_id
  inner join table5 tab5 on tab4.site_id=tab5.site_id
  inner  join(select count(component_name) as counts,device_id from table6 group by device_id) b on ?
   b.device_id =tab5.device_id
  left outer join table6 tab6 on tab5.id=tab6.id
  left outer join table7 tab7 on tab4.address_id=tab7.address_id
  where tab1.user_id='test@gmail.com'
  group by tab5.id
   order by tab5.status_priority desc;

Criteriabuilder 下面是工作代码

 Root<table1> user = criteriaQuery.from(table1.class);`
 Join<Object,Object> user2 = user.join("table2",JoinType.INNER);
 Join<Object,Object> user3 = user2.join("table3",Object> user4 = user3.join("table4",Object> user5 = user4.join("table5",Object> user6 = user5.join("table6",JoinType.LEFT);
 Join<Object,Object> user7 = user5.join("table7",JoinType.LEFT);

添加了以下几行,它可以工作,但不知道如何使用标准构建器编写

 coalesce(b.counts,0) as count `
 join(select count(component_name) as counts,device_id from table6 group by device_id) b on b.device_id  =tab5.device_id 

如何使用标准构建器 (JPQL) 为此编写子查询

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。