David542
David542

Reputation: 110205

SUBQUERY to sum up rows

The following result is created from a SELECT statement I've created:

total           date        currency    provider    conversion_to_usd
170.0168890000  2012-01-01  AUD         Telluride    1.06694
177.5532500000  2012-01-01  CAD         Telluride    1.00030
33.1864000000   2012-01-01  NZD         Telluride    0.82966
687.4900000000  2012-01-01  USD         Telluride    1.00000

How would I sum up the rows sales here, for example 170.016*1.066 + 177.55*1.00...

SELECT SUM(...) FROM <SELECT STATEMENT ABOVE> ?

Upvotes: 2

Views: 200

Answers (1)

Sebas
Sebas

Reputation: 21532

You can give the SELECT statement an alias.

This will then allow you to refer to the columns total and conversion_to_usd, to use their values on the SUM, thus, performing the required calculations:

SELECT SUM(t.total*t.conversion_to_usd) FROM (SELECT STATEMENT ABOVE) t

Upvotes: 2

Related Questions