使用RANK()OVER(),其中over是子查询的结果

时间:2017-12-06 19:14:19

标签: sql postgresql window-functions

我有以下查询产生一些我想要排名的数字,这是查询。

SELECT a.id, a.name, 
round((((select cast(count(mentions.id) as decimal) 
from mentions, events 
where mentions.event_id = events.id AND
events."startDate" < (to_date('2017-01-01', 'YYYY-MM-DD') -180) AND
mentions.person_id = a.id)
/
(select cast(count(mentions.id) as decimal) 
from mentions, events 
where mentions.event_id = events.id AND
events."startDate" < (to_date('2017-01-01', 'YYYY-MM-DD') -180) AND
mentions.person_id = 79)) * 100), 1) as lagged_person
FROM events, people, mentions
WHERE
events.id = mentions.event_id
GROUP BY a.id
ORDER BY a.name

基本上我需要做一些像RANK()OVER(lagged_person)这样的事情,当我把它作为我的下一个&#34;列&#34;在滞后的人之后,我得到一个错误,表示滞后的人不存在。我错过了什么?

0 个答案:

没有答案