Oracle11g
无论列的排序顺序如何,我都希望 rownum 按顺序出现(从最小到最大)。我可以通过通过子选择发送查询来实现这一点,如本Query所示。
问题:有没有其他方法可以让 rownum 排序独立于“order by”子句?
with alphabet as
( select 'A' as letters from dual union all
select 'B' as letters from dual union all
select 'C' as letters from dual)
select rownum, letters from
(select letters from alphabet
-- order by letters -- I can change the sort order here w/o changing rownum sort order.
order by letters desc)
如果我不进行子选择,那么我的 rownum 将按列排序,如下所示:
with alphabet as
( select 'A' as letters from dual union all
select 'B' as letters from dual union all
select 'C' as letters from dual)
select rownum, letters from alphabet
order by letters desc -- sorting here alters the rownum sort.