select query and count based on condition
问题 I want to select all categories, subcategories and count the number of business that belongs to subcategory. this is the SQl query i am using. SELECT c.id, c.name, c.slug, sc.id, sc.name, sc.slug, COUNT(bsc.id) AS business_count FROM fi_category c LEFT JOIN fi_subcategory sc ON c.id = sc.category_id AND (sc.deleted_at IS NULL) LEFT JOIN fi_business_subcategory bsc ON sc.id = bsc.subcategory_id AND (bsc.deleted_at IS NULL) WHERE (c.deleted_at IS NULL) GROUP BY c.id, sc.id however there is more