Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Print Stay Pairs only where S2 stay is not S1 stay, merge by gid
- StayPairs = π gid ← S1.gid, S1.sid, S2.sid, S1.start, S2.start, S1.nights, S2.nights (σ S1.sid != S2.sid ((ρ S1 (π sid, gid, start, nights (Stay)))
- ⨝ S1.gid = S2.gid (ρ S2 (π sid, gid, start, nights (Stay)))))
- -- Only where S2 is newer
- StayPairsNewer = σ S1.start < S2.start (StayPairs)
- -- Now filter previous table so only newer stays with longer or same duration are present
- StayPairsNewerAndLonger = σ S1.nights <= S2.nights (StayPairsNewer)
- -- Count the pairs for just newer and newer and longer
- StayNewerCounts = γ gid; count(gid) → times (StayPairsNewer)
- StayNewerAndLongerCounts = γ gid; count(gid) → times (StayPairsNewerAndLonger)
- -- Now get the table of gids where both gid and times are same, which means they are valid guests for query
- GidsForFilter = StayNewerCounts ⨝ StayNewerAndLongerCounts
- -- Now get relevant information for those guests which are present in our gids table by joining
- π id←S1.gid, name←Guest.gName, email←Guest.email ((ρ S1 (π gid (GidsForFilter))) ⨝ S1.gid=Guest.gid (Guest))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement