某表
若干字段 存的都是数字 一个字段是日期,即每一行记录的所有数字都属于这个日期的a--------------b----------c---------d---------e-----------f-------date
78-------------50---------70--------7890------782---------8-------2009-10-20
查询结果要变成
2009-10-20------ 78
2009-10-20------ 50
2009-10-20------ 70
2009-10-20------ 7890
2009-10-20------ 782
2009-10-20------ 8
若干字段 存的都是数字 一个字段是日期,即每一行记录的所有数字都属于这个日期的a--------------b----------c---------d---------e-----------f-------date
78-------------50---------70--------7890------782---------8-------2009-10-20
查询结果要变成
2009-10-20------ 78
2009-10-20------ 50
2009-10-20------ 70
2009-10-20------ 7890
2009-10-20------ 782
2009-10-20------ 8
union all
select `date`,b
union all
select `date`,c
union all
select `date`,d
union all
select `date`,e
union all
select `date`,f
order by `date`;
union all
select `date`,b from 表t
union all
select `date`,c from 表t
union all
select `date`,d from 表t
union all
select `date`,e from 表t
union all
select `date`,f from 表t
order by `date`;
select *
from(
select `date`,a as num from 表t
union all
select `date`,b from 表t
union all
select `date`,c from 表t
union all
select `date`,d from 表t
union all
select `date`,e from 表t
union all
select `date`,f from 表t
) t
where `date`=xxx
order by `date`但如果是其他数字列的话,要每个都加上条件
建议在每个后加WHERER这样速度会快一些。
+------+--------+
| id | userid |
+------+--------+
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 1 | 3 |
+------+--------+
4 rows in set (0.00 sec)mysql> select group_concat(id) from user group by userid;
+------------------+
| group_concat(id) |
+------------------+
| 1,2,3,1 |
+------------------+
1 row in set (0.00 sec)典型的列转行