We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Weather Observation Station 2
Weather Observation Station 2
Sort by
recency
|
1507 Discussions
|
Please Login in order to post a comment
SELECT ROUND(SUM(LAT_N), 2) AS lat, ROUND(SUM(LONG_W), 2) AS lon FROM STATION;
SELECT CAST(ROUND(SUM(LAT_N), 2) AS DECIMAL(10,2)), CAST(ROUND(SUM(LONG_W), 2) AS DECIMAL(10,2)) FROM STATION;
select cast(Round(sum(lat_n),2) as decimal(38,2)) as [lat], cast(Round(sum(long_W),2) as decimal(38,2)) as [lon] from station
/* Only the round doasn't get rid of the trailing zeros. So you have to cast as decimal then (38, 2). The 38 is for precision, this means you can have a total of 38 digits in total (left and right of the decimal point). The 2 is for scale, this means the number of digits that are gonna be stored agter the decimal point.
*/
SELECT CAST(ROUND(SUM(LAT_N), 2) AS DECIMAL(10,2)), CAST(ROUND(SUM(LONG_W), 2) AS DECIMAL(10,2)) FROM STATION;
Successful submission on DB2 server => calculate the sum -> round() which rounds to 2 decimal places but includes trailing zeros as well -> cast it to Decimal(10,2) to remove any trailing zeros after 2 decimal places
Why this query is not working in MY SQL Server -
SELECT ROUND(SUM(LAT_N), 2), ROUND(SUM(LONG_W), 2) FROM STATION;