freddy
freddy

Reputation: 155

MYSQL how to sum of two concatenated fields

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

Answers (2)

Walker Farrow
Walker Farrow

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

Juan Carlos Oropeza
Juan Carlos Oropeza

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

Related Questions