Created
April 17, 2019 13:41
-
-
Save Brutt/6bbb373e113be2f54cc068ce7a4a7b0d to your computer and use it in GitHub Desktop.
unpivot3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH calendar as ( | |
SELECT 1 as shop_id, 0 as mon, 0 as tue, 1 as wed, 1 as thur, 1 as fri, 0 as sat, 0 as sun FROM dual | |
UNION ALL | |
SELECT 2 as shop_id, 1 as mon, 1 as tue, 1 as wed, 1 as thur, 0 as fri, 0 as sat, 0 as sun FROM dual | |
) | |
, seq as (SELECT level as lvl FROM dual CONNECT BY level <= 7) | |
SELECT shop_id, | |
case when lvl = 1 then 'mon' | |
when lvl = 2 then 'tue' | |
when lvl = 3 then 'wed' | |
when lvl = 4 then 'thur' | |
when lvl = 5 then 'fri' | |
when lvl = 6 then 'sat' | |
when lvl = 7 then 'sun' | |
end as dayOfWeek, | |
case when lvl = 1 then mon | |
when lvl = 2 then tue | |
when lvl = 3 then wed | |
when lvl = 4 then thur | |
when lvl = 5 then fri | |
when lvl = 6 then sat | |
when lvl = 7 then sun | |
end as isWorkDay | |
FROM calendar, seq | |
WHERE shop_id = 1 | |
ORDER BY shop_id, lvl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment