Problems / Active in Every Quarter / Editorial
DATE_TRUNC('quarter', order_date)
COUNT(DISTINCT quarter)
COUNT(*)
= 4
This is relational division — "rows related to *every* member of a set" — the query shape behind "watched all episodes", "passed every audit", "stocked in all regions". The elegant trick is turning a universally-quantified condition (for all quarters: an order exists) into a counting condition (distinct quarters = size of the required set), which SQL's aggregate machinery handles in one pass. Two details carry it: DISTINCT (volume in one quarter must not fake coverage) and knowing the divisor's size — hardcode 4 only when the required set truly is fixed.
Solve Active in Every Quarter yourself →