# Weather Observation Station 13

# Weather Observation Station 13

watchitdips + 0 comments The question specifies truncating, not rounding the values. So, if i am using round(sum(lat_n),4,1) it should work. Here the third parameter prevents the function from rounding if it is not equal to 0.

But why the above is not working? Can anyone suggest?

marinskiy + 2 comments Here is Oracle solution from my HackerrankPractice repository:

SELECT ROUND(SUM(Lat_N), 4) FROM STATION WHERE Lat_N > 38.7880 AND Lat_N < 137.2345;

Feel free to ask if you have any questions :)

UPD. Solution updated, see comments for details

ghatak_ani + 1 comment select CAST(SUM(LAT_N) as Decimal(12,4)) from Station where LAT_N between 38.7880 and 137.2345;

sauce_chili + 0 comments why do you choose cast? as far as know, cast is used to transform into specific data type not "truncated" a value, please correct me if I'm wrong

koushal + 2 comments I would like to point out that BETWEEN is inclusive, but the question specifies boundaries that are not inclusive. A simple where with two conditions would suffice for this exercise.

marinskiy + 0 comments That is atually a good point. I updated the solution here and in repo. Thanks!

xiaojiazhang96 + 0 comments Thanks for this comment

sahubikash4441 + 0 comments sql server solution : select cast(sum(lat_n) as decimal(18,4)) from station where lat_n > 38.7880 and lat_n<137.2345

cvasquezr + 0 comments ORACLE

SELECT ROUND(SUM(LAT_N),4) FROM STATION WHERE LAT_N BETWEEN 38.7880 AND 137.2345;

pavankumard29 + 0 comments Oracle solution: select round(sum(lat_n),4) from station where lat_n>38.7880 and lat_n<137.2345;

codemaker3395 + 4 comments MY SQl solution: select round(sum(lat_n),4) from station where lat_n between 38.7880 and 137.2345;

nodakai + 1 comment SQL BETWEEN is inclusive, which makes it unsuitable for this exercise

subhashish_pand1 + 0 comments so just increase it by 1 and decrease 1 from suitable ends

ButtahNBred + 0 comments Inclusivity doesn't mean you can't use BETWEEN. You just have to take that into account when defining your query.

Md_Abu_Sadek + 0 comments wrong solution. anybody can imagine a counter testcase.

deliam_arlen + 0 comments This should technically fail as the requirements were that the sum is from values greater than x and less than y and the MySQL BETWEEN is inclusive but their test case obviously doesn't cover that.

`If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0.`

https://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#operator_between

Aanchal_Jain + 0 comments select TRUNCATE(SUM(LAT_N),4) from STATION where LAT_N > 38.7880 and LAT_N < 137.2345;

chkrishnakumar + 0 comments my solution fro ms SQL server:- select cast(round(sum(LAT_N),4) as decimal (10,4) ) from station where LAT_N >38.7880 and LAT_N<137.2345;

jailsonevora + 0 comments MSql Server

select CAST(ROUND(sum(LAT_N), 4) AS NUMERIC(12,4)) from station where LAT_N > 38.7880 and LAT_N < 137.2345

aiswaryakv2595 + 0 comments select round(sum(lat_n),4) from station where lat_n>38.7880 and lat_n<137.2345;

Sort 147 Discussions, By:

Please Login in order to post a comment