2
我在甲骨文11g企業版11.2.0.4.0有效的方式來查詢數據的存在分區表中
我有了每個分區約12M行的表。分區是SnapshotDate
。
我需要評估最近15天的快照是否有任何數據。
在網上找到最多答案告訴我用Row_Number() Over (Partition By SnapshotDate Order By SnapshotDate
``。這是我想出了一個代碼(它僅返回值,到目前爲止的日期,所以我需要一個左與我的日曆表連接,當然):
;With OneDateAllDates As
(
/*
partition by snapshot date so that numbering starts over again
i have to use an order by - it gave me an error without one
*/
Select SnapshotDate, 1 HasData, Row_Number() Over (Partition By SnapshotDate Order By SnapshotDate) RowNumber
From FactTable
Where SnapshotDate IN
(
/* any mechanism that gives me the last 10 calendar days will do*/
Select CalendarTimeId
From DimCalendar
Where CalendarDate Between To_Date ('20161208', 'yyyymmdd') - 15 And To_Date ('20161208', 'yyyymmdd')
)
)
Select *
From AllDates
Where RowNumber = 1;
然而,訂貨12M行超過15天瘋狂地昂貴 - 我排序1.8億行,以獲得15行。這是我期望的輸出:
Date HasData
=========== =======
12/08/2016 1
12/07/2016 1
12/06/2016 0
12/05/2016 0
12/04/2016 1
12/03/2016 0
12/02/2016 1
12/01/2016 0
etc etc
是否有更有效的方法來編寫這樣的查詢?
什麼是分區間隔? –
每日分區,每天12M行 –