Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select * from (select table_1.id, table_2.id, (table_1.quantity + table_2.quantity) as total
- from
- (select * from tables where not exists (
- select *
- from "reservations"
- inner join "reservation_tables" on "reservations"."id" = "reservation_tables"."reservation_id"
- where
- "tables"."id" = "reservation_tables"."table_id"
- and tsrange(start_at, end_at, '[]') && tsrange('2020-06-30 22:31:00', '2020-07-01 00:01:00', '[]')
- and "canceled_at" is null and "reservations"."deleted_at" is null
- ))
- as table_1,
- (select * from tables where not exists (
- select *
- from "reservations"
- inner join "reservation_tables" on "reservations"."id" = "reservation_tables"."reservation_id"
- where
- "tables"."id" = "reservation_tables"."table_id"
- and tsrange(start_at, end_at, '[]') && tsrange('2020-06-30 22:31:00', '2020-07-01 00:01:00', '[]')
- and "canceled_at" is null and "reservations"."deleted_at" is null
- ))
- as table_2
- where table_1.id != table_2.id and table_1.allow_link = true and table_2.allow_link = true
- ) as b
- where b.total >= 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement