Skip to content

Instantly share code, notes, and snippets.

@Brutt
Last active April 17, 2019 13:21
Show Gist options
  • Save Brutt/fe7c4daab83338dbb3d9a71d3613fe85 to your computer and use it in GitHub Desktop.
Save Brutt/fe7c4daab83338dbb3d9a71d3613fe85 to your computer and use it in GitHub Desktop.
Unpivot
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 shop_id, dayOfWeek, isWorkDay
FROM calendar
UNPIVOT (
isWorkDay
FOR dayOfWeek IN (mon, tue, wed, thur, fri, sat, sun)
)
WHERE shop_id = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment