选择不同的,在行尾显示计数
我有这个表/数据结构:
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
谢谢! 本
I have this table/data structure:
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"
Rows 1 and 3 have duplicate Postcodes and Areas. I need a query that outputs counts like this this:
Area Postcode Count
----------------------------
"Area 1" "EN1 1NE" 2
"Area 2" "AB2 3BA" 1
"Area 3" "XY4 5ZA" 1
"Area 4" "MN6 5OP" 1
I've searched and played about with DISTINCT and/or COUNT and/or subqueries but getting really lost here! #weak-sql-fu
Thanks!
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 count(*) 与 group by 一起使用,如下所示:
You can use count(*) with group by like this:
必须在
ALIAS
COUNT
中使用反引号来转义 RESERVED WORD。have to use backtick within the
ALIAS
COUNT
to escape the RESERVED WORD.