在sql server裡面有top關鍵字可以很方便的取出前n條記錄,但是oracle裡面卻沒有top的使用,類似實現取出前n條記錄的簡單方法如下:
方法1:利用row_number函式
取出前5條記錄:?
select
no
from
(
select
row_number() over (
order
by
no
) rno,
no
from
rownum_test
)
where
rno <= 5
order
by
no
;
取出中間5條記錄:?
12
3
select
no
from
(
select
row_number() over (
order
by
no
) rno,
no
from
rownum_test
)
where
rno
between
5
and
10
order
by
no
;
方法2:利用子查詢
取出前5條記錄:?
12
3
select
no
from
(
select
no
from
rownum_test
order
by
no
)
where
rownum <= 5
order
by
no
;
取出中間5條記錄:?
12
3
4
5
select
no
from
(
select
no
, rownum rno
from
(
select
no
from
rownum_test
order
by
no
)
)
where
rno
between
5
and
10
order
by
no
;
Oracle取兩條記錄的交集INTERSECT
摘自 intersect 操作符用來合併兩個查詢,返回兩個查詢中都存在的記錄,即返回兩個查詢結果的交集,前提是兩個查詢的列的數量和資料型別必須完全相同。select code from employee where gender m intersect select code from salary...
Hive分組排序取top N
案列 求每個班級每科成績的第1名的學生。樣例資料如下 這個是典型的分組,組內排序求top n的問題,可以利用rank函式來解決。語法如下 rank over partition by col1 order by col2 排序時出現相等的值時會有相同的序列值,但會跳躍的排序,如 1,1,3,4,5,...
access excel取隨機n條記錄
乙個簡單的問題被我搞複雜了,都不行,我一直在想著怎麼用 access 的語法來實現,也就是在 access 上面做文章,回來的時候,靈機一動,既然是 sql就應該可以用 sql的語法來實現,何況我對 access 不很熟原來的語句 select top 100 from openrowset mic...