我有以下表结构,有很多这样的表:
data_1:
+-------+--------+-------+
| views | clicks | date |
+-------+--------+-------+
| 29 | 1 | ..... |
| 458 | 9 | ..... |
+-------+--------+-------+
....
data_43:
+-------+--------+-------+
| views | clicks | date |
+-------+--------+-------+
| 0 | 0 | ..... |
| 0 | 0 | ..... |
+-------+--------+-------+
...
我的问题是,如何在一个查询中获取所有总和值?
我尝试了一个简单的连接:
mysql> SELECT SUM(t1.views) data_1_views,
SUM(t1.clicks) data_1_clicks,
SUM(t2.views) data_43_views,
SUM(t2.clicks) data_43_clicks
FROM data_1 t1, data_43 t2;
但我的结果不是我所期望的:
+--------------+---------------+---------------+----------------+
| data_1_views | data_1_clicks | data_43_views | data_43_clicks |
+--------------+---------------+---------------+----------------+
| NULL | NULL | NULL | NULL |
+--------------+---------------+---------------+----------------+
我期望它是:
+--------------+---------------+---------------+----------------+
| data_1_views | data_1_clicks | data_43_views | data_43_clicks |
+--------------+---------------+---------------+----------------+
| 487 | 10 | 0 | 0 |
+--------------+---------------+---------------+----------------+
这里有人可以帮助我解决这个问题吗?
如果这比在多个查询中执行所有这些操作更高效,我也很感兴趣