在SQL中使用相同的查询
Select count(tbl_leads.lead_Status_Id) , tbl_LeadStatus.LeadStatus_Type FROM tbl_LeadStatus LEFT JOIN tbl_leads ON tbl_LeadStatus.LeadStatus_id = tbl_leads.lead_Status_Id GROUP BY tbl_LeadStatus.LeadStatus_Type;
Hibernate查询
Select s.LeadStatus_Type, count(l.status) FROM Status s "
+ "LEFT JOIN Lead l ON l.status = s.LeadStatus_id "
+ "GROUP BY s.LeadStatus_Type"
期待输出是这个
Count LeadStatus_Type
'0' 'Cancelled'
'0' 'In-Progress'
'1' 'New'
'0' 'Sold'
'0' 'UnAssigned'
HQL返回此
'1', 'New'
答案 0 :(得分:1)
您的加入条件已关闭。在HQL中,我们从实体加入另一个实体,该实体作为第一个实体的属性存在。最重要的是,没有ON
子句,因为这种关系在Hibernate中是已知的。请尝试以下方法:
SELECT s.LeadStatus_Type, COUNT(l.status)
FROM Status s
LEFT JOIN s.LeadStatus_id l
GROUP BY s.LeadStatus_Type