I have a table:
table1
col1 col2
1 a
1 b
1 c
I want to add rownum but from a specific number, for ex. starting from 100, so it would look like:
col1 col2 rn
1 a 100
1 b 101
1 c 102
I know how to add rownum like below:
select a.*, rownum as rn from table1 a;
But I don't know how to add from a specific number. How to do it in Oracle SQL?
我认为没有必要从系统来源获取这种rownum,例如,您可以使用以下查询
select a.*, 99+rownum as rn from table1 a;
The ANSI SQL way of doing this would be to use ROW_NUMBER
:
SELECT col1, col2, 99 + ROW_NUMBER() OVER (ORDER BY col2) rn
FROM table1;
You might be able to use Oracle's ROWNUM
function here, but in that case you would also need to provide an ORDER BY
clause to your query:
SELECT col1, col2, 99 + ROWNUM AS rn
FROM table1
ORDER BY col2;
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.