gpt4 book ai didi

mysql - 选择不同的,在行尾显示计数

转载 作者:行者123 更新时间:2023-11-29 04:27:13 24 4
gpt4 key购买 nike

我有这个表/数据结构:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com