对不起,如果我的问题没有道理。 不知道我们是否只能使用mysql。 可以说我有这个查询:

SELECT SUM(win) * 100 as win_profit, date, uid FROM `tips` WHERE uid = 60 AND placed = 1 GROUP by date

显然,这将每天获得数据库中获胜栏的总和。

可以说数据库有:

|___win___|____date____|
|   10    | 2014-04-16 |
|   10    | 2014-04-16 |
|   10    | 2014-04-17 |
|   10    | 2014-04-18 |
|   10    | 2014-04-18 |
|   10    | 2014-04-18 |
|   10    | 2014-04-19 |
|   10    | 2014-04-19 |
|   10    | 2014-04-19 |

这将导致:

20
10
30
30

我如何得到它的结果,所以每个加起来,仅mysql查询。 因此结果将是:

20
30
60
90

===============>>#1 票数:2 已采纳

您可以获取所有不同的日期,然后LEFT JOIN可以找到该日期之前所有值的总和。 我保留了示例查询中的100乘数,但是您需要删除它才能获得与所需结果相匹配的结果。

SELECT 100 * SUM(b.win), a.date 
FROM (SELECT DISTINCT date FROM `tips`) a
LEFT JOIN tips b ON a.date >= b.date
GROUP BY a.date
ORDER BY a.date

要使用进行测试的SQLfiddle

===============>>#2 票数:0

这可能是另一种方式...

SET @full_sum=0;
SELECT @full_sum+SUM(win) as win_profit, date as this_date, uid, 
@full_sum:=(SELECT @full_sum+SUM(win) 
            FROM `testing` WHERE uid = 60 
            GROUP by date HAVING date=this_date) 
FROM `testing` WHERE uid = 60 GROUP by date;

  ask by user2639176 translate from so

未解决问题?本站智能推荐:

关注微信公众号