MySQL Complex query

Source: Internet
Author: User

-(SELECTNULL, product_id, Product_Name,Count(Op. Number) as  Number,--sum (total_amount + POINT_TOTAL_AMOUNT/10) asTotal_amount,--sum (point_total_amount) asPoint_total_amount-- from----(SELECT * FROM orders where (status = ' Completed ' and (Refund_status in (' refunded ', ' not_apply ')) or refund_status = ' refunded ') aso----LeftJoinOrder_products asOp on op.order_id = O.ID-LeftJoinUsers asU on u.id = O.user_id-- -- --GROUP BY product_id----O.user_id-- --GROUP BY user_id--ORDER BY product_id-- )

(SelectOrder1.user_id  as user_id, product_id, Product_Name,Count(Op. Number) as  Number, sum(Total_amount+ Convert(Point_total_amount/Ten,decimal)) asTotal_amount,sum(Point_total_amount) asPoint_total_amount from (Select *  fromOrderswhere(Status= 'completed'  and(Refund_statusinch('refunded','not_apply')))orRefund_status= 'refunded') asOrder1 Left JoinOrder_products asOp onop.order_id=order1.id Left JoinUsers asU onU.id=Order1.user_idGroup  by user_id, product_idOrder  by user_id)UNION  AllSelect NULL,user_id, Realname, Ifnull (NULL,'Total')  ,Count(*) as  Number,sum(Total_amount) asTotal_amount from(SelectOrder1.user_id  as user_id, product_id, Product_Name,Count(Op. Number) as  Number, sum(Total_amount+ Convert(Point_total_amount/Ten,decimal)) asTotal_amount,sum(Point_total_amount) asPoint_total_amount from (Select *  fromOrderswhere(Status= 'completed'  and(Refund_statusinch('refunded','not_apply')))orRefund_status= 'refunded') asOrder1 Left JoinOrder_products asOp onop.order_id=order1.idGroup  by user_id, product_idOrder  by user_id)  asNew Left JoinUsers asU onU.id=New.user_idGROUP  byNew.user_id

MySQL Complex query

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.