-(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