Transformation of records 1 column 3 row -> 1 row 3 column

Posted by Nehal Rupani on Stack Overflow See other posts from Stack Overflow or by Nehal Rupani
Published on 2010-06-03T15:17:10Z Indexed on 2010/06/03 15:24 UTC
Read the original article Hit count: 280

Filed under:
|

First look at below query

SELECT count(id) as total_record, 
  id, modeller, MONTHNAME(completed_date) as current_month,
  Quarter(completed_date) as current_quarter, Difficulty, 
  YEAR(completed_date) as current_year 
FROM model 
WHERE modeller != '' 
  AND completed_date BETWEEN '2010-04-01' AND '2010-05-31' 
  AND Difficulty != '' 
Group by Difficulty, 
  Month(completed_date) 
Order by Month(completed_date) ASC

Results I am getting is

Modeller  Month Year  Difficulty
-------------------------------------
XYZ       Jan   2010   23
XYZ       Jan   2010   14
XYZ       Jan   2010   15
ABC       Feb   2010    5
ABC       Feb   2010   14
ABC       Feb   2010    6

I want result like

Modeller Month  Year   Difficulty
--------------------------------------
XYZ      Jan    2010   23, 14, 15
ABC      Feb    2010    5, 14, 6

My database is Mysql for application i am developing so any help would be greatly appericated.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysqli