Reputation: 155
Hi Do you have idea how to sum two defined fields? is this posible?
SELECT SUM(a) as total_a, SUM(b) as total_b, (total_a + total_b) as grand_total
FROM table
if not, how can i come-up with this?
Upvotes: 1
Views: 49
Reputation: 3875
You can also do it inline as in:
SELECT SUM(a) as total_a, SUM(b) as total_b, (sum(a) + sum(b)) as grand_total
FROM table
Upvotes: 2
Reputation: 48177
You need create a subquery.
SELECT sum_ab.total_a + sum_ab.total_b as grand_total
FROM
(SELECT SUM(a) as total_a, SUM(b) as total_b
FROM table
) as sum_ab
Upvotes: 1