Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2019-1-1 00:00';
- set @start2 := CURDATE();
- select
- distinct c.coupon_policy_id as couponid,
- weekofyear((c.created_at + interval '8' hour)) as createdweek,
- concat(weekofyear((c.created_at + interval '8' hour)),"-","2019") as createdweekyear,
- c.comment as couponname,
- count(distinct case when c.activated_at >= @start then c.activated_at end) as nactivated,
- count(distinct case when c.used_at >= @start then c.activated_at end) as nused,
- if(c.expired_at > @start2, "Not Expired", "Expired") as expdate
- from coupons c
- where c.created_at + interval '8' hour > @start
- group by couponid,createdweek
- order by 2 desc
Advertisement
Add Comment
Please, Sign In to add comment