简体   繁体   中英

Is there a way to add ROW_NUMBER() without using OVER (ORDER BY ...) in SQL

Is there a way to add ROW_NUMBER() simply based on the default row order without using OVER (ORDER BY...) ?

There is no implicit ordering to rows in a table, it is a logical unordered set.

however you can do row_number() over (order by (select null))

As suggested by Itzik Ben-Gan from his book on window functions .

For PostgreSQL and MYSQL 8.0

row_number()over() 

For SQL Server and oracle it will be:

row_number()over(order by (select null))

But this without mentioning proper order by clause it's not guaranteed to have same row number for a column everytime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM