NetSide
NetSide

Reputation: 3890

AVG in Sql - Float number problem

SELECT     AVG(variable) AS Expr1, SUM(variable) AS Expr2
FROM       ......

result for AVG is 2, but it is not true, it must be 2.95. What is the problem, any idea?

Upvotes: 38

Views: 40568

Answers (2)

Della Smith
Della Smith

Reputation: 1

SELECT AVG(CAST(age)) AS average_age FROM Customer C JOIN Purchase P1 USING (customer_key) JOIN Product P USING (product_key) WHERE P.name = 'Smartwatch' AND YEAR(date) = 2024

Upvotes: 0

user110714
user110714

Reputation:

Try

Select
    AVG(Cast(variable as Float)),
    SUM(variable)
From
    Table

Upvotes: 66

Related Questions