【发布时间】:2022-01-23 21:54:57
【问题描述】:
我只有一张城市表:
| ID | Name | Country Code | District | Population |
|---|---|---|---|---|
| 6 | Rotterdam | NLD | Zuid-Holland | 593321 |
| 3878 | Scottsdale | USA | Arizona | 202705 |
| 3965 | Corona | USA | California | 124966 |
| 3973 | Concord | USA | California | 121780 |
| 3977 | Cedar Rapids | USA | Iowa | 120758 |
| 3982 | Coral Springs | USA | Florida | 117549 |
| 1613 | Neyagawa | JPN | Osaka | 257315 |
| 1630 | Ageo | JPN | Saitama | 209442 |
预期结果是:
| countrycode | avg(population) |
|---|---|
| JPN | xxxxxx |
| NLD | xxxxxxx |
| USA | xxxxxxx |
我使用了共享代码,但没有得到预期的答案:
select avg(population)
from city
where countrycode='JPN' and 'USA' and 'NLD'
group by district;
上面的代码给了我一个空白结果“avg(population)” - 空白。
我正在使用 SQL 工作台
【问题讨论】:
-
MySQL Workbench,顾名思义,是 MySQL 的 IDE,而不是 SQL Server。您真正在使用哪个?
-
尝试将“countrycode”也放入 SELECT 语句中。
-
select countrycode, avg(population) from city group by countrycode;
标签: sql