Oracle 'Partition By' and 'Row_Number' keyword

后端 未结 4 1192
南方客
南方客 2020-11-30 20:25

I have a SQL query written by someone else and I\'m trying to figure out what it does. Can someone please explain what the Partition By and Row_Number

4条回答
  •  伪装坚强ぢ
    2020-11-30 21:09

    That selects the row number per country code, account, and currency. So, the rows with country code "US", account "XYZ" and currency "$USD" will each get a row number assigned from 1-n; the same goes for every other combination of those columns in the result set.

    This query is kind of funny, because the order by clause does absolutely nothing. All the rows in each partition have the same country code, account, and currency, so there's no point ordering by those columns. The ultimate row numbers assigned in this particular query will therefore be unpredictable.

    Hope that helps...

提交回复
热议问题