Home > database >  Optimize SQL
Optimize SQL

Time:03-03

Want to ask, there are a lot of aggregation function in a SQL statement and the subquery, how should deal with to query speed faster
SELECT
IFNULL (SUM (onychoteuthis ILL_AMOUNT), 0) as orderAmount,
IFNULL (SUM (IF (o. ` STATUS `='40', onychoteuthis ILL_AMOUNT, 0)), 0) as cancelOrderAmount,
IFNULL (sum (l.L OAN_AMOUNT), 0) as loanAmount,
IFNULL (sum (IF (l. ` STATUS `='10', l.L OAN_AMOUNT, 0)), 0) as loanUndoneAmount,
IFNULL (sum (IF (l. ` STATUS `='30', l.L OAN_AMOUNT, 0)), 0) as loanDoneAmount,
Count (*) as billNumber
The FROM yqt_order_info o
Inner join sys_app_profile SSP ON SSP. App_id=o.l oan_app_id
LEFT the JOIN yqt_loan_info l ON l.o rder_id=cast (o.i d as char) AND l. STATUS!
='0'Where 1=1
And o.I D not in
(the select oinfo. ID from yqt_order_info oinfo
Inner join yqt_product_info product on the product. The product_code that starts.=oinfo loan_type
Where oinfo. Status='40' and the product. The cancel_amt_valid='N')
  • Related