计算 sql 中 table 客户在每个不同城市的客户数量

Count number of customers in each Distinct city from customer table in sql

我的数据库有一个名为 customer 的 table,其数据在以下列中:idfirst_namelast_namecity.

像这样:

现在我需要一个 table,每个 Distinct city 中有 customers 个数。 SQL 应该查询什么?

您可以使用 COUNT 聚合函数 -

SELECT city, COUNT(ID)
  FROM customer
 GROUP BY city;