德国(8000万人口)是欧洲人口最多的国家。奥地利(人口850万)拥有德国11%的人口。
显示欧洲每个国家的名称和人口。显示德国人口占总人口的百分比。
格式应为Name,Percentage,例如:
name percentage
Albania 3%
Andorra 0%
Austria 11%我的答案是
SELECT name,Concat(ROUND(population*100/(select population from world where name = 'Germany'),0),'%')
FROM world
WHERE continent = 'Europe'
name percentage
Albania 3.000000000000%
Andorra 0.000000000000%
Austria 11.000000000000%发布于 2021-06-09 13:32:38
试试CAST it吧
SELECT name, CONCAT(CAST(ROUND(population * 100/(select population from world where name = 'Germany'),0) AS INT),'%')
FROM world
WHERE continent = 'Europe'发布于 2021-06-09 13:43:33
这有点奇怪,但是下面的SQL可以在SqlZoo上运行:
select name,
concat(cast (round(100 * population / (select population from world where name = 'Germany'), 0) as int), '%')
from world
where continent = 'Europe'首先,您必须将结果转换为int,并将%符号连接到它。
https://stackoverflow.com/questions/67898069
复制相似问题