I got the core logic pretty fast but stumbled on the edge cases.
First, identify active merchants and compute their total menu item count and vegetarian item count. Then filter for merchants where total count > 0 and total count equals vegetarian count, and finally divide the count of such merchants by the total number of active merchants, multiplying by 100 to get a percentage.
Pro tip: Clarify the definition of 'active merchant' upfront—whether it's based on a status column, recent orders, or another criterion—and confirm that merchants with no menu items are excluded from the numerator but included in the denominator.
Filter the merchants table to only those with an active status (e.g., is_active = 1 or status = 'active'). This forms the base population for the denominator.
Join the filtered merchants with the menus and menu_items tables, then group by merchant to compute total item count and vegetarian item count (SUM of is_vegetarian).
Filter the grouped results to merchants where total item count > 0 and total item count equals vegetarian item count. These merchants have at least one item and all items are vegetarian.
Count the number of fully vegetarian merchants and divide by the total number of active merchants, then multiply by 100. Use a subquery or CTE to avoid division by zero and ensure correct aggregation.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.