Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;


population Surface are in KM Sq meters per person name Brazil China Germany India Japan Nigeria United States 278357000 170115000 1277558000 82164700 1013662000 26714000 111506000 8547403.00 9572900.00 357022.00 3287263.00 377829.00 923768.00 9363520.00 50244.852012 7493.123600 4345.199337 3242.957712 2981.746295 8284.468997 33638.528939 Number of rows: 25 ilter rows: Search this table

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