I have 2 table user_log and user_plan. I write a query using join :

SELECT distinct user_log.user_id,user_plan.month_plan_id 
    FROM user_plan 
    LEFT JOIN user_log ON user_plan.user_id = user_log.user_id 
    WHERE user_log.user_id != ''

Return Value:

user_id month_plan_id
1   4
1   2
1   1
43  3
43  2
46  3
74  1
74  3

But i want to customize and its looks like:

user_id month_plan_id
1   4,2,1   
43  3,2 
46  3
74  1,3

Please help me.

有帮助吗?

解决方案

use it with GROUP_CONCAT

try this:

  SELECT user_id, group_concat(month_plan_id) as month_plan_id 
  FROM your_table
  GROUP BY user_id
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top