gpt4 book ai didi

mysql - 将行与列连接 mysql

转载 作者:行者123 更新时间:2023-11-29 01:29:54 26 4
gpt4 key购买 nike

我有两个表,我需要从中选择数据

用户

id   email
----------
1 email1
2 email2

设置

usrid name    value
--------------------
1 set1 value1
1 set2 value2
2 set1 value1
2 set2 value2

我使用的sql是

SELECT u.email, s . * 
FROM `sers` u
INNER JOIN `settings` s ON u.id = s.usrid
LIMIT 0 , 30

但是我明白了

email  name value
------------------
email1 set1 value1
email1 set1 value1
email2 set2 value2
email2 set2 value1

有什么办法可以得到

email1  set1 value1 set1 value1 etc
email2 set2 value2 set2 value2 etc

我从 group_concat 尝试过这个

SELECT u.email, GROUP_CONCAT(s.name,s.value) as vals FROM `users` u INNER JOIN `settings` s ON u.id = s.usrid GROUP BY u.email

给了

email1  set1value1,set1value1 etc

我怎样才能在逗号之间的每个值之间放置一个分隔符

喜欢

email1  set1=value1,set1=value1 etc

最佳答案

使用 GROUP_CONCAT()GROUP BY

关于mysql - 将行与列连接 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com