Advertisement
copysiper

Untitled

May 26th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. -- Print Stay Pairs only where S2 stay is not S1 stay, merge by gid
  2. 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)))
  3. ⨝ S1.gid = S2.gid (ρ S2 (π sid, gid, start, nights (Stay)))))
  4.  
  5. -- Only where S2 is newer
  6. StayPairsNewer = σ S1.start < S2.start (StayPairs)
  7.  
  8. -- Now filter previous table so only newer stays with longer or same duration are present
  9. StayPairsNewerAndLonger = σ S1.nights <= S2.nights (StayPairsNewer)
  10.  
  11. -- Count the pairs for just newer and newer and longer
  12. StayNewerCounts = γ gid; count(gid) → times (StayPairsNewer)
  13. StayNewerAndLongerCounts = γ gid; count(gid) → times (StayPairsNewerAndLonger)
  14.  
  15. -- Now get the table of gids where both gid and times are same, which means they are valid guests for query
  16. GidsForFilter = StayNewerCounts ⨝ StayNewerAndLongerCounts
  17.  
  18. -- Now get relevant information for those guests which are present in our gids table by joining
  19. π id←S1.gid, name←Guest.gName, email←Guest.email ((ρ S1 (π gid (GidsForFilter))) ⨝ S1.gid=Guest.gid (Guest))
  20.  
  21.  
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement