可能重复:
MySQL 将行转换为动态列数
我有一个查询显示每天的项目数
$query = "SELECT uploadedby, count(item) as item, date_format(uploaddate, '%m-%d-%y') as date FROM `imsexport` GROUP BY uploadedby,date";
$result = mysql_query($query);
结果表如下所示
Name item date
Abel Antonio 10 01-02-12
Abel Antonio 5 01-03-12
Abel Antonio 6 01-04-12
Abel Antonio 2 01-05-12
Abel Antonio 1 01-09-12
Abel Antonio 15 01-12-12
Abel Antonio 22 01-16-12
Abel Antonio 15 01-17-12
Abel Antonio 7 01-19-12
Abel Antonio 45 02-15-12
Abel Antonio 31 02-16-12
...other names
我想将日期作为列以使查询看起来像这样
Name 01-02-12 01-03-12 01-04-12 01-05-12 01-09-12 ....
Abel Antonio 10 5 6 2 1 .....
有谁知道如何做到这一点?