[英]sql query to select record having same id but different values in two columns
I tried for hours and read many posts but I still can't figure out how to handle this request我尝试了几个小时并阅读了很多帖子,但我仍然不知道如何处理这个请求
I have a table like this我有一张这样的桌子
Name Phone
John 62778282
Alok 67828888
Rahul 68999999
Yash 97788899
John 99989999
Rahul 99992222
The output should be something like: output 应该类似于:
Name Phone
John 62778282 , 99989999
Alok 67828888
Rahul 68999999 , 99992222
Yash 97788899
Please Anybody help me to get this result请任何人帮助我得到这个结果
In this case you could use GROUP_CONCAT with GROUP BY:在这种情况下,您可以将GROUP_CONCAT与 GROUP BY 一起使用:
SELECT
`Name`,
GROUP_CONCAT(`Phone`) AS `Phone`
FROM `Table`
GROUP BY `Name`;
+=======+===================+
| Name | Phone |
+=======+===================+
| Alok | 67828888 |
| John | 62778282,99989999 |
| Rahul | 62778282,99992222 |
| Yash | 97788899 |
+-------+-------------------+
Group By
And GROUP_CONCAT
Group By
依据和GROUP_CONCAT
SELECT Name, GROUP_CONCAT(Phone) AS Phone FROM phonetable GROUP BY Name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.