Jump to content

cross tab query in mysql


mtvaran

Recommended Posts

You can accomplish it using GROUP BY but you still need to know how many Q's you have:

 

SELECT cid, 
       SUM(IF(`Q#`=1, marks, 0)) AS Q1,
       SUM(IF(`Q#`=2, marks, 0)) AS Q2,
       SUM(IF(`Q#`=3, marks, 0)) AS Q3
FROM tableName
GROUP BY cid

 

You could use PHP and another query to determine the number of Q's and dynamically build the SELECT statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.