我想进行查询,选择类别名称并计算每个类别中的最大广告(活动),我已经这样做了:
SELECT
cat.cat_id,
cat.cat_desc,
COUNT(ad_id) AS cat_total_ads
FROM
tab_categories AS cat LEFT JOIN
tab_ads AS ads ON ads.cat_id = cat.cat_id
WHERE
cat_active = @cat_active AND
cat_deleted = @cat_deleted
GROUP BY
cat_desc, cat.cat_id
此查询也在计算非活动广告。如何将非活动广告的值设为 0?