Skip to content

Instantly share code, notes, and snippets.

@IMSoP
Created September 21, 2013 20:25
Show Gist options
  • Save IMSoP/6653849 to your computer and use it in GitHub Desktop.
Save IMSoP/6653849 to your computer and use it in GitHub Desktop.
/*
table activities
activity_id int (auto-increment) primary key
name varchar
description varchar
table cabins
cabin_id int (auto-increment) primary key
name varchar
table schedules
schedule_id int (auto-increment) primary key
name varchar
created_by_user_id int (foreign key to users table, not shown)
cabin_id int (foreign key to cabins table)
table schedule_items
schedule_item_id int (auto-increment) primary key
schedule_id int (foreign key to schedules table, indicating which schedule this item belongs to)
start_time datetime -- this might just be a date, no time; it might also be a reference to an abstract "period", which then has the datetime
activity_id int (foreign key to activities table)
*/
-- Sample query:
Select
S.name as schedule_name,
C.name as cabin_name,
SI.start_time,
A.name as activity_name
From
schedules as S
Join
cabins as C
On C.cabin_id = S.cabin_id
Join
schedule_itemas as SI
On SI.schedule_id = S.schedule_id
Join
activities as A
On A.activity_id = SI.activity_id
Where
S.created_by_user_id = 42
Order by
C.cabin_name,
SI.start_time;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment