在同一个分区上应用多个窗口函数 [英] Applying Multiple Window Functions On Same Partition

查看:128
本文介绍了在同一个分区上应用多个窗口函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将多个窗口功能应用于同一个分区? (如果我使用的词汇不正确,请纠正我)

Is it possible to apply multiple window functions to the same partition? (Correct me if I'm not using the right vocabulary)

例如,您可以这样做

SELECT name, first_value() over (partition by name order by date) from table1

但是有一种方法可以执行以下操作:

But is there a way to do something like:

SELECT name, (first_value() as f, last_value() as l (partition by name order by date)) from table1

参考:
http://postgresql.ro/docs/8.4/static/tutorial-window.html

推荐答案

您不能只使用每个选择的窗口吗?

Can you not just use the window per selection

类似

SELECT  name, 
        first_value() OVER (partition by name order by date) as f, 
        last_value() OVER (partition by name order by date) as l 
from table1

也可以从您的参考资料中这样做

Also from your reference you can do it like this

SELECT sum(salary) OVER w, avg(salary) OVER w
FROM empsalary
WINDOW w AS (PARTITION BY depname ORDER BY salary DESC)

这篇关于在同一个分区上应用多个窗口函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆