b*****n 发帖数: 2324 | 1 请问这个query执行起来会efficient嘛?
http://www.codeproject.com/Articles/300785/Calculating-simple-r
SELECT a.id, a.value, (SELECT SUM(b.value)
FROM RunTotalTestData b
WHERE b.id <= a.id)
FROM RunTotalTestData a
ORDER BY a.id;
只扫描table一遍吗?谢谢 |
B*****g 发帖数: 34098 | 2 别折腾了,直接partition by
【在 b*****n 的大作中提到】 : 请问这个query执行起来会efficient嘛? : http://www.codeproject.com/Articles/300785/Calculating-simple-r : SELECT a.id, a.value, (SELECT SUM(b.value) : FROM RunTotalTestData b : WHERE b.id <= a.id) : FROM RunTotalTestData a : ORDER BY a.id; : 只扫描table一遍吗?谢谢
|
b*****n 发帖数: 2324 | 3 展开说说?谢谢!
【在 B*****g 的大作中提到】 : 别折腾了,直接partition by
|
s*********t 发帖数: 296 | 4 sql 2012可以用这个(如果a.id不unique,RANGE 和 ROW 稍有不同):
SELECT a.id, a.value, SUM(a.value) OVER (ORDER BY a.id ROWS UNBOUNDED
PRECEDING)
FROM RunTotalTestData a
ORDER BY a.id;
Oracle:
SELECT a.id, a.value, SUM(a.value) OVER (ORDER BY a.id RANGE BETWEEN
UNBOUNDED PRECEDING AND CURRENT ROW)
FROM RunTotalTestData a
ORDER BY a.id; |
A*******n 发帖数: 625 | 5 太喜欢你的回答了。 呵呵
【在 B*****g 的大作中提到】 : 别折腾了,直接partition by
|