尝试使用 NHibernate 运行以下 HQL:
select count(distinct t) as TweetCount
from Tweet t
join t.Tweeter u
left join t.Votes v
left join t.Tags tag
where t.App = :app
having count(distinct v) > 0
但是由于某种原因,有条款被忽略了,当只有 2 条推文有投票权时,它会计算所有推文。我基本上想计算至少有一个投票的推文数量。
这是我的数据库
我尝试向我的查询添加一个 group by,如下所示:
select count(distinct t) as TweetCount
from Tweet t
join t.Tweeter u
left join t.Votes v
left join t.Tags tag
where t.App = :app
group by t
having count(distinct v) > 0
...但它最终返回了一个包含 2 个整数的集合,每个整数都设置为 '1' 而不是唯一的结果。