Let's say I have a table with SellerId
, DateTime
, ProductType
to register each time a a Seller sells a product. The ProductType is from ENUM
type with { 0=Phone, 1=Recharge, 2=SimCard }. Then I have a table with SellerId
and SellerName
.
I want to write a stored procedure that shows this result:
ID | NAME | Phones | Recharges | SimCards | Total
----|------|--------|-----------|----------|-------
05 | Eddy | 6 | 7 | 0 | 13
I know how to join
the two tables to get the ID
and NAME
in this result set, but I do not know how to SUM
each ProductType
into a different column. And I also wanted only one row for each ID/NAME
.
Can anyone show me how to achieve this in this simple example?
Best Answer
This is pretty simple to code using standard SQL if that is what you prefer.
RESULTS: