hibernate查询不返回零值

6uxekuva  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(346)

在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;

休眠查询

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'

把这个还给我

'1', 'New'
jchrr9hc

jchrr9hc1#

你的加入条件看起来不好。在hql中,我们从一个实体连接到作为第一个实体的属性存在的另一个实体。最重要的是,没有 ON 子句,因为这种关系在hibernate中是已知的。请尝试以下操作:

SELECT s.LeadStatus_Type, COUNT(l.status)
FROM Status s
LEFT JOIN s.LeadStatus_id l
GROUP BY s.LeadStatus_Type

相关问题