我正在尝试使用子查询构建条件查询 . 我读了很多关于创建子查询的detachedcriteria但是找不到关于选择另一个select的任何内容(而不是where子句等上的子查询) .

每当用户与应用程序交互时,应用程序就会在交互表中向一些数据插入一行 .

我想要实现的查询是:

计算按天,按特定月份分组的所有互动,并计算同一特定月份中按天分组的所有特定互动用户 .

我可以在SQL中构建的查询是

select DAY(intsys.dateReg) all_days ,
 count(intsys.id) all_interactions, 
 (select count(us.id) from Interaction us where us.user_id = 2 and MONTH(us.dateReg) = 7 and DAY(us.dateReg) = DAY(intsys.dateReg)) user_interactions 
from Interaction intsys
where MONTH(intsys.dateReg) = 7 group by DAY(intsys.dateReg);

结果完全符合预期:

enter image description here

任何人都可以帮我使用Criteria API重现此查询吗?