|
| 1 | +WITH cards_cross_restrictions_and_snapshots AS ( |
| 2 | + SELECT |
| 3 | + cards.id as card_id, |
| 4 | + restrictions.id as restriction_id, |
| 5 | + snapshots.id as snapshot_id, |
| 6 | + snapshots.format_id as format_id, |
| 7 | + snapshots.card_pool_id as card_pool_id, |
| 8 | + snapshots.date_start as snapshot_date_start |
| 9 | + FROM |
| 10 | + cards, restrictions JOIN snapshots ON restrictions.id = snapshots.restriction_id |
| 11 | +) |
| 12 | +SELECT |
| 13 | + cards_cross_restrictions_and_snapshots.format_id, |
| 14 | + cards_cross_restrictions_and_snapshots.card_pool_id, |
| 15 | + cards_cross_restrictions_and_snapshots.snapshot_id, |
| 16 | + cards_cross_restrictions_and_snapshots.snapshot_date_start, |
| 17 | + cards_cross_restrictions_and_snapshots.restriction_id, |
| 18 | + cards_cross_restrictions_and_snapshots.card_id, |
| 19 | + restrictions_cards_banned.restriction_id IS NOT NULL |
| 20 | + OR restrictions_cards_restricted.restriction_id IS NOT NULL |
| 21 | + OR restrictions_cards_points.restriction_id IS NOT NULL |
| 22 | + OR restrictions_cards_global_penalty.restriction_id IS NOT NULL |
| 23 | + OR restrictions_cards_universal_faction_cost.restriction_id IS NOT NULL |
| 24 | + as in_restriction, |
| 25 | + CASE WHEN restrictions_cards_banned.restriction_id IS NOT NULL THEN true ELSE false END AS is_banned, |
| 26 | + CASE WHEN restrictions_cards_restricted.restriction_id IS NOT NULL THEN true ELSE false END AS is_restricted, |
| 27 | + COALESCE(restrictions_cards_points.value, 0) AS eternal_points, |
| 28 | + COALESCE(restrictions_cards_universal_faction_cost.value, 0) AS universal_faction_cost |
| 29 | +FROM |
| 30 | + cards_cross_restrictions_and_snapshots |
| 31 | + JOIN card_pools_cards ON card_pools_cards.card_pool_id = cards_cross_restrictions_and_snapshots.card_pool_id |
| 32 | + AND card_pools_cards.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 33 | + LEFT OUTER JOIN restrictions_cards_banned ON |
| 34 | + restrictions_cards_banned.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id |
| 35 | + AND restrictions_cards_banned.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 36 | + LEFT OUTER JOIN restrictions_cards_points ON |
| 37 | + restrictions_cards_points.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id |
| 38 | + AND restrictions_cards_points.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 39 | + LEFT OUTER JOIN restrictions_cards_global_penalty ON |
| 40 | + restrictions_cards_global_penalty.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id |
| 41 | + AND restrictions_cards_global_penalty.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 42 | + LEFT OUTER JOIN restrictions_cards_restricted ON |
| 43 | + restrictions_cards_restricted.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id |
| 44 | + AND restrictions_cards_restricted.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 45 | + LEFT OUTER JOIN restrictions_cards_universal_faction_cost ON |
| 46 | + restrictions_cards_universal_faction_cost.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id |
| 47 | + AND restrictions_cards_universal_faction_cost.card_id = cards_cross_restrictions_and_snapshots.card_id |
| 48 | +; |
0 commit comments