MySQL:与其他数据的累积计数给出了错误的输出

时间:2015-01-22 11:41:35

标签: mysql

我正在尝试创建一个表来按日期获取累计销售额,并尝试将总流量数据(只是值)添加到同一个表中。虽然我的累积计数是完美的,但total_traffic计数完全错误。

如果我将总流量作为单独的查询运行,则答案是完美的。不知道我在这里做错了什么

select a.date, (@cumulative := @cumulative + a.sales) AS cumulative, "" as total_traffic 
FROM  
(select date, sales  
 from table1
 group by date  
 order by date) AS a, (SELECT @cumulative:=0) AS n
UNION
select "" as date, "" as cumulative, sum(traffic) as total_traffic from table2

0 个答案:

没有答案