Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
3 列のテーブルがあり、列ヘッダーは、職場、居住地、通勤者数 (ジオコード、ジオコード、番号) です。職場ごとに、最も一般的な居住地のトップ 5 と通勤者数を知りたいです。SQLでこれを行う方法についてのアイデアはありますか?
どの RDBMS を使用しているかはわかりませんが、これは SQL Server で動作するはずです。
with MyCTE AS ( select *, RANK() OVER (PARTITION BY placeOfWork ORDER BY NumberOfCommuters DESC) AS Rank from PlacesOfWorkWork ) select * from MyCTE where Rank <= 5