我有以下查询,
SELECT n.id, network_name, count(DISTINCT a.id), count(DISTINCT w.id), count(DISTINCT v.id)
FROM network n
LEFT JOIN account a ON a.network_id = n.id
LEFT JOIN meat w ON w.account_id = a.id
LEFT JOIN fish v ON v.account_id = a.id
GROUP BY n.id, network_name
为什么要使用QueryDSL构造相同的SQL查询我需要"反转"一些逻辑?如果方法的顺序和名称可以与SQL匹配,那么这不容易吗?
这是我需要创建的查询才能获得相同的结果。我有相当多的时间来理解这个逻辑。
new JPAQuery(entityManager).from(meat, fish)
.rightJoin(meat.account, account)
.rightJoin(fish.account, account)
.rightJoin(account.network, network)
.groupBy(network)
.where(network.id.eq(id))
.singleResult(network, account.id.countDistinct(), fish.id.countDistinct(), meat.id.countDistinct());
有些观点: