Hibernate 在HQL的构造函数查询中使用distinct with Column Value
我想根据数据库中不同的实验室编号检索记录。 我遇到的问题是,患者有多个实验室,多个实验室编号存储在连接的表中。Hibernate 在HQL的构造函数查询中使用distinct with Column Value,hibernate,hql,Hibernate,Hql,我想根据数据库中不同的实验室编号检索记录。 我遇到的问题是,患者有多个实验室,多个实验室编号存储在连接的表中。 我的问题是: Select distinct new org.laborders.dto.LabOrderDTO(ps.labNumber,ps.patientServiceId, ps,patientName,pso.patientServiceOrderId,pso.totalAmount) from patientServices ps join patientServi
我的问题是:
Select distinct new org.laborders.dto.LabOrderDTO(ps.labNumber,ps.patientServiceId,
ps,patientName,pso.patientServiceOrderId,pso.totalAmount)
from patientServices ps join patientServicesOrder pso
我想在ps.labNumber上检索唯一的记录您这样做过吗-
Select distinct new org.laborders.dto.LabOrderDTO(ps.labNumber,ps.patientServiceId,
ps,patientName,pso.patientServiceOrderId,pso.totalAmount)
from patientServices ps join patientServicesOrder pso
看,我先放置了关键字distinct,然后是new package.class。我在@Query中遇到了与“distinct+构造函数”类似的问题。 我找到的解决方案是重写查询,如下所示:
Select new org.laborders.dto.LabOrderDTO(ps.labNumber,ps.patientServiceId,
ps,patientName,pso.patientServiceOrderId,pso.totalAmount)
from patientServices ps join patientServicesOrder pso
GROUP BY ps.labNumber,ps.patientServiceId,
ps,patientName,pso.patientServiceOrderId,pso.totalAmount
对所有select列使用GROUP BY与使用DISTINCT具有相同的效果
我使用的是Spring数据JPA和Hibernate