窗函數我有我的,我只是想不通SELECT語句。查詢如下:PostgreSQL中
SELECT
count(1),
interaction_type_id
FROM
tibrptsassure.d_interaction_sub_type
GROUP BY
interaction_type_id
HAVING
count(interaction_type_id) > 1
ORDER BY
count(interaction_type_id) DESC
LIMIT 5;
由於我的應用程序不支持使用LIMIT關鍵字,我試圖改變使用rank()
功能,像這樣我的查詢:
SELECT
interaction_type_id,
rank() OVER (PARTITION BY interaction_type_id ORDER BY count(interaction_type_id)
DESC)
FROM
tibrptsassure.d_interaction_sub_type;
但是,這樣一來我結束了以下錯誤消息:
ERROR: column "d_interaction_sub_type.interaction_type_id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT interaction_type_id, rank() OVER (PARTITION BY inter...
^
********** Error **********
ERROR: column "d_interaction_sub_type.interaction_type_id" must appear in the GROUP BY clause or be used in an aggregate function
SQL state: 42803
Character: 9
是否存在的rownum()
PostgreSQL中的相同呢? (除了使用LIMIT關鍵字來達到同樣的效果,那就是。)
是否有人對我有什麼建議嗎?提前致謝。
這是什麼意思:「我的*應用程序*不支持限制」?編程語言,PostgreSQL,ORM?考慮提供一個SQLFiddle演示,並將你的SQL命令格式化爲源代碼。 – Beryllium
Intelliview Nxt ..我們用來創建報告的門戶。這不支持限制功能。 – Nancy
但它*支持*窗口aggegate函數*(通過...分區...)?所以你可以改變查詢使用聚合函數,但不使用限制?換句話說,你可以在你的查詢中使用什麼? – Beryllium