所需产出:
2017年-2018年
1):夏洛克:侦探2:埃隆·马斯克:天才3):狮子座:英雄
2015-2016年
1):罗宾:侦探2):卡普里奥:英雄
2014-2015年
1):雪:英雄2):x先生:未知
Mysql Table:
+----+------------+----------+---------------------------+--------+
| id | date_from | | name | desc
+----+------------+----------+---------------------------+--------+
| 1 | 2014-2015 | snow | hero |
| 2 | 2014-2015 | Mr.x | unknown |
| 3 | 2015-2016 | Robin | detective |
| 4 | 2015-2016 | Caprio | hero |
+----+------------+----------+---------------------------+--------+我可以插入数据,但是如何像输出那样排序。
发布于 2018-03-16 08:39:47
select date_from,GROUP_CONCAT(' ',name,' : ',`desc`) as name_desc
from Table1 group by date_from输出:
date_from name_desc
2014-2015 snow : hero,Mr.x : unknown
2015-2016 Robin : detective,Caprio : hero在上述结果之后
select Concat('Date ',date_from,' ',GROUP_CONCAT(' ',name,' : ',`desc`)) as name_desc
from
Table1
group by date_from输出
name_desc
Date 2014-2015 snow : hero, Mr.x : unknown
Date 2015-2016 Robin : detective, Caprio : herohttp://sqlfiddle.com/#!9/e7a6ca/32
https://stackoverflow.com/questions/49316192
复制相似问题