我有这个表/数据结构:
ID Area Postcode
------------------------
1 "Area 1" "EN1 1NE"
2 "Area 2" "AB2 3BA"
3 "Area 1" "EN1 1NE"
4 "Area 3" "XY4 5ZA"
5 "Area 4" "MN6 5OP"
第 1 行和第 3 行具有重复的邮政编码和区域。我需要一个像这样输出计数的查询:
Area Postcode Count
----------------------------
"Area 1" "EN1 1NE" 2
"Area 2" "AB2 3BA" 1
"Area 3" "XY4 5ZA" 1
"Area 4" "MN6 5OP" 1
我已经搜索并尝试使用 DISTINCT 和/或 COUNT 和/或子查询,但在这里真的迷路了! #weak-sql-fu
谢谢! 本
最佳答案
您可以像这样将 count(*) 与 group by 一起使用:
select Area, Postcode, count(*) from TABLE group by Area, Postcode;
关于mysql - 选择不同的,在行尾显示计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192777/