sql - How to avoid duplicating statements with grouping functions? -
i have t-sql query sum function duplicated. how avoid duplicating statements?
select id, sum(value) sometable group id having sum(value) > 1000
it table aliasing not supported. think with
should work:
with tmptable (id,sumv) (select id, sum(value) sumv sometable group id ) select id, sumv tmptable sumv>1000
and fiddle:
Comments
Post a Comment