这种查询要求的SQL语句应该如何写

WBOY
Release: 2016-06-13 12:19:19
Original
847 people have browsed it

这种查询要求的SQL语句应该怎么写
表如下

A               B            
中国          1
中国          2
中国          3
美国          4
美国          5
英国          6
英国          7
.
.
.

-------------------最终查询出来结果要求是下面这样的
中国             1,2,3
美国             4,5
英国             6,7

我之前过直接用GROUP BY ,但A字段是能分组出来,但B字段的集合怎么出现呀?难道要再嵌一个SQL???
------解决思路----------------------

select A, group_concat(B) as B from 表 group by A
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!