ahmedrahil786

F5 - W_Coupon

May 18th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. set @start := '2019-1-1 00:00';
  2. set @start2 := CURDATE();
  3.  
  4. select
  5. distinct c.coupon_policy_id as couponid,
  6. weekofyear((c.created_at + interval '8' hour)) as createdweek,
  7. concat(weekofyear((c.created_at + interval '8' hour)),"-","2019") as createdweekyear,
  8. c.comment as couponname,
  9. count(distinct case when c.activated_at >= @start then c.activated_at end) as nactivated,
  10. count(distinct case when c.used_at >= @start then c.activated_at end) as nused,
  11. if(c.expired_at > @start2, "Not Expired", "Expired") as expdate
  12. from coupons c
  13. where c.created_at + interval '8' hour > @start
  14. group by couponid,createdweek
  15. order by 2 desc
Advertisement
Add Comment
Please, Sign In to add comment