简体   繁体   English

Oracle Sql 开发人员(选择计数) Twoc 列

[英]Oracle Sql Developer (Select Count) Twoc olumns

I have to make a query that has the Total number of customers by country and city我必须查询按国家和城市划分的客户总数

country and city are columns that are inside the customer table country 和 city 是客户表中的列

On my own I have managed to get the total number of customers per city like this:我自己已经设法获得每个城市的客户总数,如下所示:

SELECT city, COUNT (*)
FROM employees
GROUP BY city
ORDER BY city

But how do I get it together with the country?但我如何与国家团结起来呢? looking for information I think it should be something like this and ordered from largest to smallest找资料我觉得应该是这样的,从大到小排序

Country国家 City城市 TOTAL_CUSTOMERS TOTAL_CUSTOMERS 个客户
USA美国 Kirkland柯克兰 3 3个
USA美国 London伦敦 2 2个
UK英国 Redmond雷蒙德 2 2个
UK英国 Seattle西雅图 1 1个
UK英国 Tacoma塔科马 1 1个

What we have been told is to say Total number of customers by country and city.我们被告知的是按国家和城市划分的客户总数。

You simply add country to the column list and group by list:您只需将国家/地区添加到列列表并按列表分组:

SELECT country,city, COUNT(*)
FROM employees
GROUP BY country,city
ORDER BY COUNT(*) DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM