2017-03-07 97 views
0

我有一個名爲availableTimeslot的數據庫表,其中的字段爲pk,startDate,endDate,例如,有關日期的Oracle SQL查詢

PK startDate    endDate 
1. 2017-03-07 09:00:00 2017-03-07 18:00:00 
2. 2017-03-07 18:00:00 2017-03-07 21:00:00 
3. 2017-03-08 09:00:00 2017-03-08 18:00:00 

記錄從開始到09:00:00 18:00:00表明它是一個上午時間段,同時表明它18:00:00至23:00:00是下午時段

存儲可供客戶選擇的時間日期(例如2017-03-06,2017-03-08)。

我可以使用一個查詢從訂單日期後的第二天開始準確獲得10個可用時間段嗎?

例如如果我訂購產品。2016年3月7日,則該查詢返回

2017-03-08 09:00:00 
2017-03-08 18:00:00 
2017-03-09 09:00:00 
2017-03-09 18:00:00 
2017-03-10 ... 
2017-03-11 ... 
2017-03-13 ... 

12是在表中的公衆假期,而不是。

總之,它返回10日(具有上午和下午班,每天5天)

備註:可用的時隙日期是爲了,但可能不會是連續的

+0

編輯你的問題,並提供樣本數據和預期結果。 –

回答

0
select available_date 
from (select available_date, row_number() over (order by available_date) as rn 
     from your_table 
     where available_date > :order_date 
     ) 
where rn <= 5; 

:order_date是綁定變量 - 通過接口由用戶/客戶輸入的日期。

0

你想5對於單個客戶?

select ts.* 
from (select ts.* 
     from customer c join 
      timeslots ts 
      on ts.date > c.orderdate 
     where c.customerid = v_customerid 
     order by ts.date asc 
    ) ts 
where rownum <= 5 
+0

感謝您的回答,但我的查詢只需要滿足一個表 –