Complex Filtering

PHOTO EMBED

Thu Apr 09 2026 15:10:55 GMT+0000 (Coordinated Universal Time)

Saved by @yasvanthM

SELECT MAX(eligible_countries)
FROM (
    SELECT f.NAME, COUNT(c.ID) AS eligible_countries
    FROM FAMILIES f
    JOIN COUNTRIES c ON f.FAMILY_SIZE BETWEEN c.MIN_SIZE AND c.MAX_SIZE
    GROUP BY f.ID, f.NAME
) AS family_counts;
content_copyCOPY

Question 2: Family Tour Eligibility (Complex Filtering) The Scenario: This is a logic-heavy problem frequently cited in LinkedIn and Reddit reports. You have a FAMILIES table (ID, Name, FamilySize) and a COUNTRIES table (ID, Name, MinSize, MaxSize). Task: Print the maximum number of discounted tours that any single family can choose based on their size. The Logic: A family can visit a country if their FAMILY_SIZE is between the MIN_SIZE and MAX_SIZE (inclusive) for that country.