0

I have 2 tables below:

Table1
+-----------+------------+-----------+-----------+
| date      | TRAFFIC1   | PAYLOAD11 | PAYLOAD12 |
+-----------+------------+-----------+-----------+
|2015-01-01 | 2          | 2         | 2         |
|2015-01-01 | 3          | 3         | 3         |
|2015-01-02 | 2          | 2         | 2         |
|2015-01-02 | 3          | 3         | 3         |
+-----------+------------+-----------+-----------+

Table2
+-----------+------------+-----------+-----------+
| date      | TRAFFIC21  | PAYLOAD21 | PAYLOAD22 |
+-----------+------------+-----------+-----------+
|2015-01-01 | 2          | 2         | 2         |
|2015-01-01 | 3          | 3         | 3         |
|2015-01-02 | 2          | 2         | 2         |
|2015-01-02 | 3          | 3         | 3         |
+-----------+------------+-----------+-----------+

I want to sum payload from 2 tables above group by date?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

Try like this:

SELECT SUM(t1.payload)+SUM(t2.payload) AS total FROM table1 AS t1,table2 AS t2 GROUP BY date

for more check this: Query SUM for two fields in two different tables

Community
  • 1
  • 1
0
SELECT date, SUM(payload) FROM (
SELECT date, `PAYLOAD11` + `PAYLOAD12` as payload FROM Table1
union all
SELECT date, `PAYLOAD21` + `PAYLOAD22` as payload FROM Table2) grp
GROUP BY date

SQLFIDDLE

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70