我正在使用的查询:
SELECT COUNT(*),
SUM(amount) AS amount,
FROM_UNIXTIME(added, '%W (%e/%m)') AS daily
FROM affiliates_earnings
WHERE added >= '1319074836'
AND added <= '1319679636'
GROUP BY daily
输出:
+----------+--------+-------------------+
| COUNT(*) | amount | daily |
+----------+--------+-------------------+
| 1 | 195 | Tuesday (25/10) |
| 4 | 470 | Wednesday (26/10) |
+----------+--------+-------------------+
我想显示的是:
+-------+----------+--------+-------------------+
| i |COUNT(*) | amount | daily |
+-------+----------+--------+-------------------+
| 1 | 1 | 195 | Tuesday (25/10) |
| 2 | 4 | 470 | Wednesday (26/10) |
+-------+----------+--------+-------------------+
本质上
i
是序列号(即1,2,3,4,5,6 ...)。我将如何完成?
最佳答案
如果没有ROW_NUMBER(),则可以per this answer或this one对其进行伪造:
SELECT @i := @i + 1 AS i, COUNT(*), ...
FROM affiliates_earnings
JOIN (SELECT @i := 0) dummy
WHERE ...
GROUP BY ...;
关于mysql - 相当于MySQL $ i++,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7910989/