SQL ROWNUM (+thing I didn't know while ordering with ROWNUM&subquery)

탱귤생귤·2023년 5월 2일

SQL

목록 보기
8/13

When I saw this query, I thought why teacher is not initializing rownum and I googled what is "rownum".

This is what I found;

"Numbers the output of a result set. More specifically, returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition."
https://learn.microsoft.com/en-us/sql/t-sql/functions/row-number-transact-sql?view=sql-server-ver16

So this is a basic variable in sql.

select*from(
	select*from(
		select rownum as rn, b.* from(
			(select * from board order by num desc) b
		)
	)where rn>=1
)where rn<=10;

When I looked at this code, I didn't want to set (select * from board order by num desc) this code as b and I wrote a new code;

select * from(
	select * from(
		select rownum as rn, b.* from (
			select * from board order by num desc
		)
	)where rn>=11
)where rn<=20;

How did it end?

ORA-00933: SQL command not properly ended

When I have a subquery, I have to set a name for it.

0개의 댓글