Hello Everybody and thank you in advance for your help!
I am trying to create a crosstab type query result based on a returned query. The first query :
SELECT DISTINCT
dc.`name`,
Count(pd.dispositionCodeId) AS NumberOfDispos
FROM
pd
JOIN ph ON (pd.packetHeaderId = ph.packetHeaderId)
JOIN sc ON (sc.packetHeaderId = ph.packetHeaderId)
JOIN dc ON pd.dispositionCodeId = dc.dpcodeId
WHERE (`ph`.`customerId` = 60)
GROUP BY
dc.`name`
resulting in:
Name NumberofDispos
B 400
NO 245
S 134
V 98
-- The name
that I'm returning are variable depending on the customerId, and also on additional where clauses that appear on other similar queries.
Is there a way to pivot the results of the name
field as column headings in a second table, which a second query will count the occurances of that particular name showing up in another matched field?
B NO S V
PackA 250 120 61 22
PackB 100 23 62 37
PackC 50 102 11 39
Please keep in mind the column headings are variable based on the results fromt the first query.
As far as I can tell, I would need to make a php array and iterate through the sql results