简体   繁体   English

如何使用SQL插入小数点和四舍五入

[英]How to insert decimal point and round using SQL

Data set is from https://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial , number 9数据集来自https://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial ,编号 9

I am using我在用

SELECT name, ROUND(population, 3,0), ROUND(GDP, 3,0)
FROM world
WHERE continent = 'South America' 

Answer should be答案应该是

name        
Argentina   42.67   477.03
Bolivia 10.03   27.04
Brazil  202.79  2254.11

I am getting我正进入(状态

name        
Argentina   42669500    477028000000
Bolivia 10027254    27035000000
Brazil  202794000   2254109000000

... ...

You want the population in millions and GDP in billions, both rounded to two decimals.你想要以百万为单位的人口和以十亿为单位的 GDP,两者都四舍五入到两位小数。 Consider:考虑:

SELECT name, ROUND(population/1000000, 2), ROUND(GDP/1000000000, 2)
FROM world
WHERE continent = 'South America' 

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

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