hi guys, i am struggling with cross tab query in mysql. if you have any idea could you please help me? basically i have data into the table like...

cid | Q# | marks
c1 | 1| 50
c1 | 2 | 50
c1 | 3 | 50

but i need to be display the data like...

cid | Q1 | Q2 | Q3
c1 | 50 | 50 | 50

select cid,
  sum(case when question=1 then marks else 0 end) as Q1,
  sum(case when question=2 then marks else 0 end) as Q2,
  sum(case when question=3 then marks else 0 end) as Q3
 from test
 group by cid
 order by cid;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.