メニュー
Amazon Redshift
データベース開発者ガイド (API Version 2012年12月1日)

NTH_VALUE ウィンドウ関数の例

次の例は、州のその他の会場の座席数を比較して、カリフォルニア、フロリダ、およびニューヨークで 3 番目に大きい会場の座席数を示しています。

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)