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:

http://sqlfiddle.com/#!6/0d3f2/2


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -