21 - 即时食物配送 II
-- sum(if(order_date=customer_pref_delivery_date,1,0))/count(*)=sum(order_date=customer_pref_delivery_date)/count(*)
-- count(*),表示数据的行数,如果有分组,为分组后数据的行数select round(100*sum(if(order_date=customer_pref_delivery_date,1,0))/count(*),2) immediate_percentage
fromDelivery
where (customer_id,order_date) in (selectcustomer_id,min(order_date)from Deliverygroup bycustomer_id);