sql - mysql sum union results -


see below sample. if id, a, b, d same other records, union , sum column "c" .

my data: id  b  c  d --------------------------- 1  1  2  3  4 2  aa bb 10 dd 3  1  2  3  4 4  1  2  3  4 2  aa bb 30 dd  how after below result: id  b  c  d --------------------------- 1  1  2  3  4 2  aa bb 40 dd    <----if id,a,b,d same other records,then union , sum column "c" 3  1  2  3  4 4  1  2  3  4  tried union records,but fail , show" id  b  c  d --------------------------- 2  aa bb 49 dd  

just use group id, a, b, d sum(c) this:

select id, a,  b,  sum(c) c,  d tablename group id, a, b, d; 

sql fiddle demo


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -