你好,我有一张表W/下面的信息。
agent (agent_id, salary, city, country)我在试着询问这个请求.
“列出至少有6个城市的每个国家的代理商人数和总工资。”
我的问题是如何对不稳定的国家进行分组,并统计与国家有关的城市数量。我不太确定如何执行所需的子查询或group by子句。我试着做以下的事情。
select COUNT(agent_id) as numOfAgents, SUM(salary) as Salary, DISTINCT country
from agent
where city = (select COUNT(city) from agent where city > '5')我知道这个查询不起作用,我需要以某种方式引入group子句。
发布于 2016-01-31 20:41:11
这是HAVING语句的GROUP BY子句的谓词:
SELECT COUNT(agent_id) AS numOfAgents, SUM(salary) as Salary, country
FROM agent
GROUP BY country
HAVING COUNT(DISTINCT city) > 5出现在COUNT子句中的HAVING聚合函数计算每个国家的不同城市数。
https://stackoverflow.com/questions/35119193
复制相似问题