001 2013-1-10 100
002 2013-1-10 200
001 2013-1-11 50
002 2013-1-11 80
001 2013-1-12 300
得到
用户,日期, 当日消费金额,累计消费金额
001 2013-1-10 100 100
002 2013-1-10 200 200
001 2013-1-11 50 150
002 2013-1-11 80 280
001 2013-1-12 300 450
实现方式如下:
mysql支持:
SELECT FIELD1,FIELD2,FIELD3,
( SELECT SUM(FIELD3)
FROM TEST_AA
WHERE FIELD1 = A.FIELD1
AND FIELD2 <= A.FIELD2
) AS FIELD4
FROM TEST_AA A
( SELECT SUM(FIELD3)
FROM TEST_AA
WHERE FIELD1 = A.FIELD1
AND FIELD2 <= A.FIELD2
) AS FIELD4
FROM TEST_AA A
但hive不支持这个。
mysql实现方式二:(QQ网友西瓜小王子(365742944) 提供 ):