select CountryCode,Language, floor(max(percentage)) as speakers
from countrylanguage
group by CountryCode;
根据直觉,我希望语言与表countrylanguage中的最大百分比相对应。然而,这似乎不起作用。我应该在这里换什么才能工作?
更多信息:
desc countrylanguage;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| CountryCode | char(3) | NO | PRI | | |
| Language | char(30) | NO | PRI | | |
| IsOfficial | enum('T','F') | NO | | F | |
| Percentage | float(4,1) | NO | | 0.0 | |
+-------------+---------------+------+-----+---------+-------+
最佳答案
select CountryCode, Language, floor(percentage) as speakers
from countrylanguage c
where percentage = (select max(percentage) from countrylanguage c2 where c2.countrycode = c.countrycode group by c2.countrycode)
关于mysql - 为什么我无法为此查询获取正确的行字段?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39784055/