0
我有與感興趣3個字段的表T: d(日期),PID(INT),和評分(數字)前N個值在窗框
我試圖計算第四字段是每個玩家的前N(3或5)分數的平均值。
我嘗試以下加入一個子查詢,但它不生產我在尋找的結果:
SELECT t.d, t.pid, t.score, sq.highscores
FROM t, (SELECT *, avg(score) as highscores FROM
(SELECT *, row_number() OVER w AS rnum
FROM t AS t2
WINDOW w AS (PARTITION BY pid ORDER BY score DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING)) isq
WHERE rnum <= 3) sq
WHERE t.d = sq.d AND t.pid = sq.pid
任何建議,將不勝感激!我是一個業餘愛好者程序員,這比查詢更復雜。
如果您提供了一些示例值,那麼它會更有幫助。 –