Mysql join two tables and add column values
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-05-10T16:00:53Z
Indexed on
2010/05/10
16:04 UTC
Read the original article
Hit count: 289
My knowledge of mysql is not very in depth. If I have two tables that for example look like this:
Table1
Date v1 v2 v3
05/01/2010 26 abc 45
05/02/2010 31 def 25
05/03/2010 50 ghi 46
Table2
Date v1 v2 v3
05/01/2010 42 jkl 15
05/02/2010 28 mno 14
05/03/2010 12 pqr 64
How can I join them in a query by their date and have the sum of table1.v1 and table2.v1 and also have the sum of table1.v3 and table2.v3. V2 should be ignored.
© Stack Overflow or respective owner