mysql 複雜查詢

來源:互聯網
上載者:User

標籤:rom   div   group   查詢   nio   mount   pre   apply   products   

 

 

-- (select null, product_id, product_name, count(op.number ) as number,-- sum(total_amount + point_total_amount/10) as total_amount,-- sum(point_total_amount) as point_total_amount  -- from -- -- (select * from orders where (status = ‘completed‘ and (refund_status in (‘refunded‘,‘not_apply‘))) or refund_status = ‘refunded‘) as o-- -- left join order_products as op on op.order_id = o.id -- left join users as u on u.id = o.user_id-- -- -- group by product_id-- -- o.user_id-- -- group by user_id-- order by product_id-- )

 

(select order1.user_id as user_id, product_id, product_name,count(op.number ) as number, sum(total_amount + convert( point_total_amount/10, decimal)) as total_amount,sum(point_total_amount) as point_total_amount  from (select * from orders where (status = ‘completed‘ and (refund_status in (‘refunded‘,‘not_apply‘))) or refund_status = ‘refunded‘) as order1left join order_products as op on op.order_id = order1.id left join users as u on u.id = order1.user_idgroup by user_id,product_idorder by user_id)UNION Allselect null,user_id, realname, IFNULL(null,‘合計‘)  ,count(*) as number, sum(total_amount) as total_amount from(select order1.user_id as user_id, product_id, product_name,count(op.number ) as number, sum(total_amount + convert( point_total_amount/10, decimal)) as total_amount,sum(point_total_amount) as point_total_amount  from (select * from orders where (status = ‘completed‘ and (refund_status in (‘refunded‘,‘not_apply‘))) or refund_status = ‘refunded‘) as order1left join order_products as op on op.order_id = order1.id group by user_id,product_idorder by user_id) as newleft join users as u on u.id = new.user_idGROUP BY new.user_id

 

mysql 複雜查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.