Question

I want to write a query over with a SQL query like the following:

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

I am not able to figure out queryover in nhibernate for this. Any help will be appreciated.

No correct solution

OTHER TIPS

You are very close. You just need to alias the subquery...

SELECT count(x.customer)
FROM (SELECT customer, sales, date FROM salestable GROUP BY customer, sales, date) x

...where x is the alias. (You can also say "as x" if that helps make it obvious. Technically, you don't need the prefix in the main select either, but I always find it helpful as a general habit to avoid confusion with other tables being joined, or tables in the subquery.

Please note, this will not select distinct customers, just any instance. If you want distinct, that may vary depending on which database you are using. For SQL Server, if would just be SELECT(DISTINCT x.customer)...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top