表参见图片1
图片2是我现在的查询结果,但是我希望得到的结果是每个member_id的数据都在一行。希望各位会sql能帮我看看怎么改一下。十分感谢
我个人解决方法是
SELECT t.member_id,group_concat(t.01),group_concat(t.02),group_concat(t.03),group_concat(t.04),group_concat(t.05),group_concat(t.06),group_concat(t.07),group_concat(t.08),group_concat(t.09)
from
(select member_id,
case schedule_date when '2015-11-01' then group_concat(project_id) end as '01',
case schedule_date when '2015-11-02' then group_concat(project_id) end as '02',
case schedule_date when '2015-11-03' then group_concat(project_id) end as '03',
case schedule_date when '2015-11-04' then group_concat(project_id) end as '04',
case schedule_date when '2015-11-05' then group_concat(project_id) end as '05',
case schedule_date when '2015-11-06' then group_concat(project_id) end as '06',
case schedule_date when '2015-11-07' then group_concat(project_id) end as '07',
case schedule_date when '2015-11-08' then group_concat(project_id) end as '08',
case schedule_date when '2015-11-09' then group_concat(project_id) end as '09'
from bsddsys.schedule_data
group by member_id,schedule_date) t
group by member_id
不过感觉应该有更简单 效率更好的方法 希望知道的前辈能指点一下 谢谢
http://blog.csdn.net/xiangnideshen/article/details/39076339
把group by 中的schedule_date 去掉
SELECT
MEMBER_ID,
MAX(CASE WHEN ...
...
FROM
group by MEMBER_ID