Groupby Sum in mySQL? -


my table below:

devicenumber  payway  money     000001             1    000002       b       2    000001             1    000001       b       1.2    000002             2.6 

i want result:

   devicenumber  total        b      000001      3.2    2      1.2      000002      4.6    2.6    2 

is there sql achieve this? thank much!

yes, can use sum , case this

select devicenumber,sum(money) total,     sum(         case              when payway='a' money else 0         end) a,     sum(         case              when payway='b' money else 0         end) b mytable group devicenumber order devicenumber 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -