Nothing in this billing database is ever physically deleted. A row is removed by setting its deleted_at timestamp; deleted_at is NULL while the row is live. That applies to both tables:
- •
accounts (account_id, plan, deleted_at) - •
subscriptions (subscription_id, account_id, status, deleted_at)
Count the active subscriptions per plan. A subscription counts when its status is 'active', it isn't deleted, and its account isn't deleted. Every plan that appears in accounts must be listed, with 0 when it has no active subscriptions.
Columns: plan, active_subs. Sort by plan.