sql - How to remove the column in group by -


i working on query want mg.actid appear select column not within group by because not listing results want. group structure getting spoiled if have in group by. please let me know how retain in select column , remove group by.

want group by sr.rsrcid, sr.frsntnm, sr.lstm

query :

select (sr.lstnm+ ', '+ sr.frstnm) 'employee name',  mg.actid goalid,  sr.rsrcid empid,  count(mg.actid) '# goals',  sum(case        when prntactid != '' 1        else 0      end) '# aligned'   tm.sresource sr      left outer join tm.matrixgoal mg           on sr.rsrcid = mg.rsrcid , mg.delflg = 0  mg.activeflg = 1 group  sr.rsrcid,sr.lstnm,sr.frstnm order sr.lstnm,sr.frstnm 

one way use 'partition by' clause in aggregate functions (like sum , count), , select distinct rows data set. effectively, move group statement partition each aggregate, this:

select distinct (sr.lstnm+ ', '+ sr.frstnm) 'employee name',  mg.actid goalid,  sr.rsrcid empid,  count(mg.actid) on (partition sr.rsrcid,sr.lstnm,sr.frstnm) '# goals',  sum(case        when prntactid != '' 1        else 0      end) on (partition sr.rsrcid,sr.lstnm,sr.frstnm) '# aligned'   tm.sresource sr      left outer join tm.matrixgoal mg           on sr.rsrcid = mg.rsrcid , mg.delflg = 0  mg.activeflg = 1 order sr.lstnm,sr.frstnm 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -