查询领取张数
SELECT
a.id,
a.coupon_name 优惠券名称,
COUNT(b.member_register_id) 领取次数
FROM ad_coupons a JOIN ad_member_register_coupons b
ON a.id=b.coupon_id
GROUP BY b.coupon_id
HAVING b.coupon_id in (231,227)
查询领取人数
SELECT
a.id,
a.coupon_name 优惠券名称,
COUNT(DISTINCT b.member_register_id) 领取人数
FROM ad_coupons a JOIN ad_member_register_coupons b
ON a.id=b.coupon_id
GROUP BY b.coupon_id
HAVING b.coupon_id in (231,227)
查询使用使用张数
SELECT
a.id,
a.coupon_name,
count(b.member_register_id) 使用数量
FROM
ad_coupons a LEFT JOIN ad_member_register_coupons b on a.id=b.coupon_id
WHERE
a.id IN (231,227)
and b.used_status=1
GROUP BY
b.coupon_id
查询使用人数
SELECT
a.id,
a.coupon_name,
count(DISTINCT b.member_register_id) 使用数量
FROM
ad_coupons a LEFT JOIN ad_member_register_coupons b on a.id=b.coupon_id
WHERE
a.id IN (231,227)
and b.used_status=1
GROUP BY
b.coupon_id