在一年中查找假期的SQL查询

时间:2018-05-03 07:41:28

标签: sql oracle

我有一个表格,其中列是年份,货币和第三列由100001字符串组成,并且它继续,其中1代表假日,0代表该特定年份的工作日。 我有这样的表 -

Currency      Current year    Date values
Dollar             2017                 100111000 till 365
Rupee            2016                  111000010 till 366
Rupee            2000                  11110011 till 366

我需要编写一个选择查询,该查询将返回所有1的位置,即假期以及该特定年份的日期。 我希望以

格式输出该选择查询
Currency      year     date of holiday
Dollar            2017     01/01/2017

就像它会继续,直到它列出2017年的所有假期 然后它将继续其他年份。 我需要通过connect编写一个select语句。

1 个答案:

答案 0 :(得分:1)

使用数字表格和复杂的join

with n as (
      select rownum as n from dual connect by level <= 366
     )
select currency, year,
       (to_date(year || '-01-01') + n.n - 1) as holiday_date
from t join
     n
     on substr(t.datevalues, n.n, 1) = '1';