Home > database >  MYSQL CASE WHEN the index
MYSQL CASE WHEN the index

Time:01-11

Function is the sales statistics yesterday, today's sales
To the query conditions where the value is different, different execution plan,

Article 1 data number is 0, 0 data article number is 72 the entire table is 77 data

Instead of less than records query type is ref
For the record are ALL



Establish index below



 
Explain the SELECT
COALESCE (sum (CASE WHEN mo. Pay_status=0 THEN mo. Actual_amount END), 0) AS 'todayAmount,
COALESCE (sum (CASE WHEN mo. Pay_status=0 THEN mo. Actual_amount END), 0) AS 'yesterdayAmount,
COALESCE (sum (CASE WHEN mo. Pay_status=0 THEN mo. Actual_amount END), 0) AS 'totalAmout'
The FROM
Mall_order mo
WHERE
Mo. Tenant_group_code='1'

  • Related