Created
April 17, 2019 13:36
-
-
Save Brutt/24ab2eb81121449e29794e8a83792ea2 to your computer and use it in GitHub Desktop.
unpivot2
This file contains 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 | |
) | |
SELECT * FROM ( | |
SELECT shop_id, 'MON' as dayOfWeek, mon as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'TUE' as dayOfWeek, tue as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'WED' as dayOfWeek, wed as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'THUR' as dayOfWeek, thur as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'FRI' as dayOfWeek, fri as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'SAT' as dayOfWeek, sat as isWorkDay | |
FROM calendar | |
UNION ALL | |
SELECT shop_id, 'SUN' as dayOfWeek, sun as isWorkDay | |
FROM calendar | |
) | |
WHERE shop_id = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment