SQL programming I need to truncate numbers on a table and Im not sure how to do
ID: 3873668 • Letter: S
Question
SQL programming
I need to truncate numbers on a table and Im not sure how to do that.
Based on the table below I need to modify the query to,
Display surface area with 0 places after the decimal point
Display the sq meters per person to 2 places after the decimal point.
and here is my code so far.
SELECT name, population, (SurfaceArea * 1) AS 'Surface are in KM',
( SurfaceArea/population * 1000000 )AS 'Sq meters per person'
FROM country;
Explanation / Answer
select name, population, round(surfacearea, 0) as 'Surface are in KM', round(CAST(surfacearea*1000000 AS float) / CAST(population AS float),2) as 'Sq meters per person' from country round is required to round the float values round(1.23,0) will give 1 only without the digits after decimal point round(1.2345, 2) will give 1.23 which means it is rounding to 2 digits after decimal point Math you put was incorrect surfacearea/population*1000000 and it should be surfacearea*1000000/population To get the float value as output, we should cast numarator and denominator as float values separately
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.