sql server - T-SQL- Sum over Partition by in combination with group by -


i'm trying sum on partition normal sql statement code won't work. technology: sql server 2014

here's code:

select        zabf$,zunr$,zonr$,fpln$,zstr$,right(left(gabs$,3),2) region      ,sum(nettobetrag) nettoumsatz     ,sum(bruttobetrag) bruttoumsatz     ,sum(nettobetrag) on (partition zabf$,zunr$,zonr$,fpln$,right(left(gabs$,3),2))       archivzbew.prod.sfcts_g195      nettobetrag<>0 , right(left(gabs$,3),2)<>'65'      , utyp$ in('k','m','p') group     zabf$,zunr$,zonr$,fpln$,zstr$,right(left(gabs$,3),2) 

as can see, try output columns in first line , different sums. nettoumsatz , bruttoumsatz working fine, expected - need sum ignores "zstr$" field. take query part of cte , nice have in statement, otherwise have join table twice , statement gets slow.

errorcode: (in german):

die archivzbew.prod.sfcts_g195.nettobetrag-spalte ist in der auswahlliste ungültig, da sie nicht in einer aggregatfunktion und nicht in der group by-klausel enthalten ist.

thanks google translate:

the archivezbew.prod.sfcts_g195.nettobetrag column invalid in selection list because not contained in aggregate function , not contained in group clause.

thats - guys - big thought fault of mine - here's result:

select  distinct          zabf$,zunr$,zonr$,fpln$,zstr$,right(left(gabs$,3),2) region          ,sum(nettobetrag) on (partition zabf$,zunr$,zonr$,fpln$,zstr$,right(left(gabs$,3),2)) nettoumsatz         ,sum(bruttobetrag) on (partition zabf$,zunr$,zonr$,fpln$,zstr$,right(left(gabs$,3),2)) bruttoumsatz         ,sum(nettobetrag) on (partition zabf$,zunr$,zonr$,fpln$,right(left(gabs$,3),2))               archivzbew.prod.sfcts_g195              --nettobetrag<>0           right(left(gabs$,3),2)<>'65'           , utyp$ in('k','m','p') 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -