gpt4 book ai didi

php - 3 统计字段中唯一值的实例

转载 作者:行者123 更新时间:2023-11-29 02:00:05 26 4
gpt4 key购买 nike

我有一个类似的表,其中包含 countryregiontown 等字段。我正在尝试创建一个查询,按地区和国家/地区计算独特城镇的数量。即,如果有两条 town="Newtown"的记录,我需要看到 Newtown 的计数为 1 而不是 2。

以下查询显示包含给定城镇的记录数,但不显示唯一城镇的数量。

SELECT COUNT(town) AS numb, `country`, `region`, `town` 
FROM `table`
GROUP BY `country`, `region`, `town`

有人知道我是怎么做到的吗?

最佳答案

count() 中使用 distinct

SELECT `country`, `region`, COUNT(distinct town) AS numb
FROM `table`
GROUP BY `country`, `region`

关于php - 3 统计字段中唯一值的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17214573/

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