MySQL business-issued coupons for user usage _20161028

Source: Internet
Author: User

Operating department to give users coupons, if you want to monitor the use of coupons coupon usage rate is a good indicator of the effect

The following SQL is the daily use of coupons issued for a particular user on a given day after the release date

SELECTE. City, E. User id,i. Contact number, H. Order date, H. Order id,h, H. Order Amount, E. Coupon id,e. Coupon name, Case  whenH. Preferential amount is NULL  Then"Coupon Not used"ELSE"Use coupon"END  aswhether the issued restaurant uses coupons, E. Coupon stalls, H. Offer from (    SELECTA1. City, A1. User id,date (A1. Release date) asRelease date, A1. Coupon id,a1. Coupon name, Right(A1. Coupon name, char_length (A1. Coupon name)-Char_length ( Left(A1. Coupon name, INSTR (A1. Coupon name, "" ")-1))) asCoupon Stalls from' A015_customer_coupon ' asA1WHEREA1. City=Hangzhou andA1. Date of issue>=" .-Ten- at" andA1. Date of issue<" .-Ten- -" andA1. Coupon ID>=939  andA1. Coupon ID<=951     GROUP  byA1. User ID) ase Left JOIN (    SELECTF.*, G. Coupon id,g. Coupon Name, G. Offer from (        SELECTF1. City, F1. User id,date (Order date) asOrder date, F1. Order ID,F1. Sales clerk,SUMAmount asOrder Amount from' A003_order ' asF1WHEREF1. Amount>0  andF1. Order Date>=" .-Ten- -" andF1. Order Date<" .- One- -"         GROUP  byF1. Order ID) asF Left JOIN (            SELECTB1. City, Date (B1. Use time) asDate of use, B1. User id,b1. Order number, B1. Coupon id,b1. Coupon name,SUM(B1. Coupon amount) asDiscount Amount from' A016_order_customercoupon_xref ' asB1WHEREB1. City=Hangzhou andB1. Use time>=" .-Ten- -" andB1. Use time<" .- One- -" andB1. Coupon ID>=939  andB1. Coupon ID<=951             GROUP  byB1. Order number) asG onG. Order number=F. Order ID) asH onE. User ID=H. User ID Left JOIN' A001_resterant ' asI onI. User ID=e. User IDWHEREE. Coupon Stalls<>"No coupon"ORDER  byFIELD (whether the issuing restaurant uses coupons, "coupon", "Coupon Not used")

MySQL business-issued coupons for user usage _20161028

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.