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
from
Delivery
where
(customer_id,order_date) in
(select
customer_id,min(order_date)
from
Delivery
group by
customer_id);