简体   繁体   中英

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

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
USA Kirkland 3
USA London 2
UK Redmond 2
UK Seattle 1
UK Tacoma 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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