聚合函数
select DATE_FORMAT(trans_date, '%Y-%m') AS month,country,count(1) as trans_count,COUNT(IF(state = 'approved', 1, NULL)) AS approved_count,sum(amount) as trans_total_amount,SUM(IF(state = 'approved', amount, 0)) AS approved_total_amountfrom Transactionsgroup by month, country
select round (sum(order_date = customer_pref_delivery_date) * 100 /count(*),2) as immediate_percentagefrom Deliverywhere (customer_id, order_date) in (select customer_id, min(order_date) from Delivery group by customer_id);
SELECTROUND((select count(1)from Activitywhere (player_id, event_date) in(select player_id, DATE_ADD(MIN(event_date), INTERVAL 1 DAY)from Activitygroup by player_id)) /(SELECT COUNT(DISTINCT player_id)FROM Activity),2) AS fraction;
加油啦!加油鸭,冲鸭!!!