我在 oracle 中有一個下表

如您所見,開始日期是 20 年 11 月 4 日。我需要將 2021 年 11 月 4 日至 2021 年 11 月 10 日計為第 1 周,將 2021 年 11 月 11 日至 2021 年 11 月 17 日計為第 2 周,依此類推。我怎樣才能在 oracle 中實作這個值。
uj5u.com熱心網友回復:
您可以通過將to_char函式與WW、W或IW組合來檢查周數。
select to_char(column,'WW') from table;
WW Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
W Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IW Week of year (1-52 or 1-53) based on the ISO standard.
uj5u.com熱心網友回復:
通過計算一年中的密集排名和WW周數。
SELECT g.* , DENSE_RANK() OVER (PARTITION BY game_id ORDER BY TO_CHAR(start_date, 'YYYYWW')) as num FROM gamestarts gGAME_ID | START_DATE | NUM ------: | :--------- | --: 899 | 2020-11-04 | 1 899 | 2020-11-05 | 1 899 | 2020-11-06 | 1 899 | 2020-11-07 | 1 899 | 2020-11-08 | 1 899 | 2020-11-10 | 1 899 | 2020-11-09 | 1 899 | 2020-11-11 | 2 899 | 2020-11-12 | 2
在這里測驗db<>fiddle
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/422045.html
標籤:
上一篇:在附加列中顯示用戶的上一個日期
