计算 sql 中 table 客户在每个不同城市的客户数量
Count number of customers in each Distinct city from customer table in sql
我的数据库有一个名为 customer
的 table,其数据在以下列中:id
、first_name
、last_name
和 city
.
像这样:
现在我需要一个 table,每个 Distinct city
中有 customers
个数。 SQL
应该查询什么?
您可以使用 COUNT 聚合函数 -
SELECT city, COUNT(ID)
FROM customer
GROUP BY city;
我的数据库有一个名为 customer
的 table,其数据在以下列中:id
、first_name
、last_name
和 city
.
像这样:
现在我需要一个 table,每个 Distinct city
中有 customers
个数。 SQL
应该查询什么?
您可以使用 COUNT 聚合函数 -
SELECT city, COUNT(ID)
FROM customer
GROUP BY city;