2017-07-28 103 views
0

在這個SQL查詢中有25條記錄 我想得到5到10之間。我該怎麼做? 我用11克Oracle數據庫Rownum之間

select 
(
    select count(*) as sayfasayisi 
    from konular t 
    where t.kategori is not null 
) as sayfasayisi, 
t.id, 
t.uye, 
t.baslik,t.mesaj,t.kategori,t.tarih, 
t.edittarih,t.aktif,t.indirimpuani,t.altkategori,t.link, 
nvl(
    (select case when t.id = f.konuid and f.uye = 'test' then '1' else '0' end 
    from takipkonu f where t.id = f.konuid and f.uye = 'test'), '0') as takip 
from konular t 
where t.kategori is not null 
+0

Oracle不會爲記錄分配永久行號,所以如果您要查找表中的第5到第10條記錄,請知道它不能保證你每次都會得到相同的記錄。對於您的具體問題,您需要查看您僅檢索這些記錄的具體要求。 – Incognito

+0

您可以使用'ROW_NUMBER()'進行一定的排序,然後只保留第5到第10條記錄。 [見這裏](https://stackoverflow.com/questions/7480243/sql-oracle-order-by-and-limit)。 –

回答

0

您可以使用ROW_NUMBER()基於包含在當前的查詢,例如一些排序邏輯分配行號某一列。然後,只保留第5到第10條記錄:

select t.* 
from 
(
    select 
    (
     select count(*) as sayfasayisi 
     from konular t 
     where t.kategori is not null 
    ) as sayfasayisi, 
    ROW_NUMBER() OVER (ORDER BY some_col) rn, 
    t.id, 
    t.uye, 
    ... 
) t 
where t.rn between 5 and 10;