由于水平原因,博客大部分内容摘抄于网络,如有错误或者侵权请指出,本人将尽快修改

聚合函数

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_amount
from Transactions
group by month, country 
select  round (
    sum(order_date = customer_pref_delivery_date) * 100 /
    count(*),
    2
) as immediate_percentage
from Delivery
where  (customer_id, order_date) in (select customer_id, min(order_date) from Delivery group by customer_id);
SELECT
    ROUND(
        (select count(1)
        from Activity
        where (player_id, event_date) in
              (
                  select player_id, DATE_ADD(MIN(event_date), INTERVAL 1 DAY)
                  from Activity
                  group by player_id
              )) /
        (SELECT COUNT(DISTINCT player_id)
         FROM Activity),
    2) AS fraction;
 
posted @ 2024-07-07 16:10  小纸条  阅读(9)  评论(0编辑  收藏  举报