我试图找出累计拥有75%所有积分的顶级用户。
表是:
在此用户列表中,结果必须是用户(迪克,玛丽,杰克和山姆)。
我尝试(Oracle select ..)
SELECT o.users, SUM (o.points)
FROM (SELECT users,
SUM (points),
RANK () OVER (ORDER BY SUM (points) DESC) r
FROM points_tbl) o;
- >错误是:
ORA-00904:" o"。"积分":无效的标识符
答案 0 :(得分:2)
Oracle 11g R2架构设置:
SELECT "user", points
FROM (
SELECT p.*,
COALESCE(
SUM( points ) OVER (
ORDER BY points DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
),
0
) / SUM( points ) OVER () AS pct
FROM points p
ORDER BY points DESC
)
WHERE pct < .75
查询1 :
| user | POINTS |
|------|--------|
| mary | 45 |
| jack | 32 |
| dick | 25 |
| sam | 18 |
<强> Results 强>:
#define DEBUG_PRINT(tag, format, ...) printf("[%10s] %7d: " format "\n", tag, millis(), ##__VA_ARGS__)