Hello I am new to mysql have two tables
order
with the following data
No | Customer |
---|---|
1 | A |
1 | c |
2 | b |
second table is
Customer | Amount |
---|---|
A | 1 |
A | 2 |
C | 7 |
B | 5 |
the two table ara joined by customer I want to sum the amount grouped by No
The result expected is: Details
No | Customers | Amount |
---|---|---|
1 | A,c | 10 |
2 | b | 5 |
You can use group_concat
select t1.No, group_concat(distinct t1.Customer) Customers,sum(Amount) Amount
from tbl1 t1
join tbl2 t2 on t1.Customer = t2.Customer
group by t1.No