Sunday 18 August 2013

count items from 1 column and split them into two columns

count items from 1 column and split them into two columns

i have a two tables, data and agentdata. data (agentid, SimCardNumber,
ProductName, Agentemail)
agentdata (id, agentid, ProductName)
currently i deal only two products and i want to view this list as group
by agentemail
agentemail | Product1 | Total1 | Product2 | Total2
abc@gmail.com | ball | 5 | bat | 0
i tried this query but i have problem to show two products and their count
side by side.
SELECT a.agentid, d.Agentemail, a.ProductName, COUNT(a.ProductName) AS Total
FROM data AS d, agentdata AS a
WHERE d.agentid=a.agentid
GROUP BY a.ProductName

No comments:

Post a Comment