MySqlGROUP_CONCAT每次执⾏语句时数据顺序变化sql语句:
SELECT
u.user_id AS userId,
GROUP_CONCAT(uc.user_car_id) AS userCarId,
GROUP_CONCAT(uc.plate_no) AS plateNo
FROM
customer_user AS u
JOIN customer_user_info AS ui
mysql语句顺序
ON u.user_id = ui.user_id
JOIN customer_user_car AS uc
ON u.user_id = uc.user_id
WHERE uc.is_delete = 0
AND u.store_number = 10001
AND uc.store_number = 10001
GROUP BY u.user_id
执⾏第⼀次:
注意这两字段,顺序会发⽣变化。
执⾏第⼆次:
执⾏第三次:
可以看到,每次执⾏,数据顺序都会发⽣变化。
解决:
SELECT
u.user_id AS userId,
GROUP_CONCAT(
uc.user_car_id
ORDER BY uc.user_car_id
) AS userCarId,
GROUP_CONCAT(uc.plate_no
ORDER BY uc.plate_no) AS plateNo
horizon中文意思
FROM
customer_user AS u
JOIN customer_user_info AS ui
ON u.user_id = ui.user_id
嵌入式开发培训班
JOIN customer_user_car AS uc
splice视频编辑app免费版ON u.user_id = uc.user_id
WHERE uc.is_delete =0开源程序派单系统
dedecms转pbootcms
AND u.store_number =10001
AND uc.store_number =10001
GROUP BY u.user_id
只需要在GROUP_CONCAT()⾥⾯加上ORDER BY 数据的顺序就不会发⽣变化了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。