Home > Mobile >  Sum function in Redshift ignoring decimal values
Sum function in Redshift ignoring decimal values

Time:01-20

I have a column named myh. It has decimal values like: 65.20, 56.49

When I tried to sum up in Redshift using sum(), it is showing the result as 121 and it is ignoring the decimal values.

Is there any solution to get decimals also?

CodePudding user response:

You can use Round function for addition of values. Also you can use CAST

DECLARE @A DECIMAL(13,5)
DECLARE @B DECIMAL(13,5)
SET @A = 65.20
SET @B = 56.49

SELECT CAST(@A @B AS decimal)

SELECT ROUND(SUM(@A @B),2)

CodePudding user response:

Have you tried to Cast it?

Example:

SELECT SUM(CAST(myh as decimal(10,2)))
  •  Tags:  
  • Related