| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|||
|
There are several ways you could try this. The easisest however (but probably not the most efficient) is to use a subquery.
SELECT |
|
|||
|
This is specific to MySQL. This will give you a running sum. The last row will have the total sum of all the ages.
SET @a := 0; |
|
|||
|
Not answering the general question, merely a solution to your concrete example:
SELECT age*10 AS xyz,t.* FROM my_table JOIN (SELECT sum(age) * 10 FROM my_table) tNotes: 1) The sum is computed just once and returned as a table of cardinality 1. The table is then joined with my_table. The whole statement requires two full table scans on my-table. 2) (A x 10) + (B x 10) = (A + B) x 10 |
![]() |
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|