首先按用户分组,内容按也按用户分组用"|"隔开成为一个字段
贴sql:
SELECT
s.id,
s.uid,
s.qid,
s.create_time,
w.title,
(
group_concat(s.qid, '|', avalue, '|', qtype)
) AS avalues
FROM
wenjuan_select AS s
LEFT JOIN question AS q ON s.qid = q.qid
LEFT JOIN wenjuan AS w ON w.id = s.id
WHERE
s.id = 86
AND create_time >= '2021-05-17 00:00:00'
AND create_time <= '2021-06-17 23:59:59'
GROUP BY
uid
ORDER BY
create_time DESC
LIMIT 0,
16
查询出来的数据是这样的:
group_concat 默认长度限制 临时修改
group_concat查询做字段数据合并的时候会,长度过长会被截取,可以临时修改配置:
SET SESSION group_concat_max_len=102400;
然后在查询的时候,数据就全部显示出来了,如果还是有问题,试着加大配置的数。