Amazon Redshift
数据库开发人员指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

NTH_VALUE 开窗函数示例

以下示例显示了加利福利亚、佛罗里达和纽约的第三大场地的座位数与这些州的其他场地的座位数的比较情况:

Copy
select venuestate, venuename, venueseats, nth_value(venueseats, 3) ignore nulls over(partition by venuestate order by venueseats desc rows between unbounded preceding and unbounded following) as third_most_seats from (select * from venue where venueseats > 0 and venuestate in('CA', 'FL', 'NY')) order by venuestate; venuestate | venuename | venueseats | third_most_seats ------------+--------------------------------+------------+------------------ CA | Qualcomm Stadium | 70561 | 63026 CA | Monster Park | 69843 | 63026 CA | McAfee Coliseum | 63026 | 63026 CA | Dodger Stadium | 56000 | 63026 CA | Angel Stadium of Anaheim | 45050 | 63026 CA | PETCO Park | 42445 | 63026 CA | AT&T Park | 41503 | 63026 CA | Shoreline Amphitheatre | 22000 | 63026 FL | Dolphin Stadium | 74916 | 65647 FL | Jacksonville Municipal Stadium | 73800 | 65647 FL | Raymond James Stadium | 65647 | 65647 FL | Tropicana Field | 36048 | 65647 NY | Ralph Wilson Stadium | 73967 | 20000 NY | Yankee Stadium | 52325 | 20000 NY | Madison Square Garden | 20000 | 20000 (15 rows)