Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL HAVE SUM GROUP BY

Puoi avere una selezione interna, come:

SELECT count_of_foo, count(bar), baz
FROM (SELECT count(foo) as count_of_foo, bar, baz, other1, other2 FROM complex_query WHERE foo = bar HAVING count(foo) > 1) inner_query
GROUP BY count_of_foo, baz.

Questo ti darà la possibilità di aggiungere più gruppi dopo la clausola HAVING.