sql - Group by on multiple columns using Aggregate functions -


i had following table structure listed below

budhol    cocode    ben      obj    spare2  spare1  taskno  value   fieldnamenew     362103  36      362101  991003  null    ma1001  null    4516    613030     362103  36      362101  991003  null    ma1001  null    9088    613030     362103  36      362101  991003  null    ma1001  null    3387    613030     362103  36      362101  991003  null    ma1001  null    4026    613030 

below required output

 budhol   cocode    ben      obj    spare2  spare1  taskno  value   fieldnamenew     362103  36      362101  991003  null    ma1001  null    21017   613030 

i.e value should sumed if columns same i.e. sum of value column

below query have tried value not coming properly

select b.ben,        b.budhol,        b.cocode,        b.fieldnamenew,        b.obj,        b.spare1,        b.spare2,               sum(b.value)as value #temp4 (     select distinct a.ben,                     a.budhol,                     a.cocode,                     a.fieldnamenew,                     a.obj,                     a.value,                     a.spare2,                     a.spare1           #temp3     left join #temp3 t1 on a.ben = t1.ben         , a.budhol = t1.budhol         , a.cocode = t1.cocode         , a.obj = t1.obj         , a.spare1 = t1.spare1         , a.spare2 = t1.spare2         , a.fieldnamenew = t1.fieldnamenew ) b group b.ben,          b.budhol,          b.cocode,          b.obj,          b.fieldnamenew,          b.spare1,          b.spare2 

based on write, simpler query work:

select b.ben, b.budhol, b.cocode, b.fieldnamenew, b.obj, b.spare1, b.spare2,               sum(b.value) value #temp4 #temp3 b group b.ben, b.budhol, b.cocode, b.fieldnamenew, b.obj, b.spare1, b.spare2; 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -