简体   繁体   English

sql 带 ROUND 和除法的查询

[英]sql query with ROUND and division

Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros).显示 GDP 至少为一万亿(1000000000000;即 12 个零)的国家的名称和人均 GDP。 Round this value to the nearest 1000. Show per-capita GDP for the trillion dollar countries to the nearest $1000.将该值四舍五入到最接近的 1000。将万亿美元国家的人均 GDP 显示到最接近的 1000 美元。

SELECT name ,
       ROUND(gdp/population,0.01)

from world
where gdp >= 1000000000000

this however produces bugs.然而,这会产生错误。

The task can be tested here任务可以在这里测试

The second argument to round is the number of digits after or before the decimal. round 的第二个参数是小数点后或前的位数。 I would start with:我会从:

select name ,
       ROUND(gdp/population, -3)
from world
where gdp >= 1000000000000

A negative number is before the decimal place.小数点前为负数。 You can read the documentation .您可以阅读文档

用这个

SELECT name, capital FROM world WHERE length(name) = length(capital)

You can also try this:你也可以试试这个:

 SELECT NAME, ROUND(GDP/population * 0.001, 0) * 1000 as "PER-CAPITA GDP" 
         FROM WORLD WHERE GDP>= 1000000000000

:) #mysql :) #mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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