select - Group Concat in mysql statement -


i've got table called delitems colums.

within select statement want use group_concat:

 +-------------------------------+-------+--------+--------+-----+  | color                         | total | ptotal | amount | qty |  +-------------------------------+-------+--------+--------+-----+  | blue - w = 55,blue - w/o = 93 |   148 |    375 |  55500 |   2 |  +-------------------------------+-------+--------+--------+-----+  mysql>select group_concat(color,' = ',qty) color, sum(qty) total, sum(p_cost)  ptotal, sum(qty)*sum(p_cost) amount,count(*) qty delitems status='3' group cont_no; 

everything works fine except amount column. total amount wrong! here correct value:

+-----------------+-------+--------+--------+-----+ | color           | total | ptotal | amount | qty | +-----------------+-------+--------+--------+-----+ | blue - w = 55   |    55 |    125 |   6875 |   1 | | blue - w/o = 93 |    93 |    250 |  23250 |   1 | +-----------------+-------+--------+--------+-----+ mysql>select group_concat(color,' = ',qty) color, sum(qty) total, sum(p_cost) ptotal, sum(qty)*sum(p_cost) amount,count(*) qty delitems status='3' group color; 

i want display in 1 line correct total amount

please help.

should need sum(a*b) not sum(a)*sum(b)

select     group_concat(color,' = ',qty) color  , sum(qty) total  , sum(p_cost)  ptotal  , sum(qty*(p_cost) amount, count(*) qty  delitems  status='3' group cont_no; 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -