Nhibernate 带子查询的查询结束

Nhibernate 带子查询的查询结束,nhibernate,queryover,Nhibernate,Queryover,我想用SQL查询编写一个查询,如下所示: select sum(customer) from ( select customer, sales, date from salestable group by customer, sales, date ) as x 我无法在nhibernate找到这个问题的答案。任何帮助都将不胜感激。您非常接近。您只需要将子查询别名为 SELECT count(x.customer) FROM (SELECT customer, sal

我想用SQL查询编写一个查询,如下所示:

select sum(customer) from
(
   select customer, sales, date 
     from salestable
    group by customer, sales, date
) as x

我无法在nhibernate找到这个问题的答案。任何帮助都将不胜感激。

您非常接近。您只需要将子查询别名为

SELECT count(x.customer)
FROM (SELECT customer, sales, date FROM salestable GROUP BY customer, sales, date) x
…其中x是别名。你也可以说x,如果这有助于让它变得明显的话。从技术上讲,您也不需要在主select中使用前缀,但我始终发现,作为一种常规习惯,避免与正在联接的其他表或子查询中的表混淆是很有帮助的


请注意,这不会选择不同的客户,只是选择任何实例。如果您希望使用不同的数据库,这可能会因您使用的数据库而异。对于SQL Server,如果选择Distinct x.customer…

谢谢您的回答。我的问题是如何将此查询转换为NHibernate上的queryover为什么需要子选择?您不能只写:从salestable中选择sumcustomer吗?您不能使用QueryOver从子查询中选择。您必须重写查询,可能正如@perpuum所建议的那样。不,在我的真实数据库中,列是不同的。这只是为了说明逻辑是相同的