以下是我的sql查询,其中我试图获取那些地址相同的人的名字,但我面临的问题是查询显示正确的计数,但所有的名称都没有分组而不是以下方式。请告诉我如何修改以下查询,以便我能够以下面提到的方式获取地址,并且还应忽略count(address)= 1。谢谢,
+---------------------+ Jhon | Stree 9, H#4 zame | Stree 9, H#4 sinn | Stree 9, H#4 linn | Stree 8, H#9 tinn | Stree 8, H#9 +---------------------+
SELECT *,count(address) FROM `student`
group by address
order by count(address) desc
SQLFIDDLE: http://sqlfiddle.com/#!2/6d6ca/2
答案 0 :(得分:3)
试试这个:
SELECT name, count(address) FROM student
GROUP BY address
ORDER BY count(address), name DESC
编辑: 你的意思是这个group_concat?
SELECT GROUP_CONCAT(DISTINCT name ORDER BY name DESC SEPARATOR ' ')as name,
adress FROM student
GROUP BY adress
ORDER BY count(adress), name DESC