题解 | 下单复盘

下单复盘

https://www.nowcoder.com/practice/85cece6c8e11434783e9e18da2bddd45

select
customers.customer_id 
,customer_name 
,count(distinct orders.order_id) feb_2024_order_count
,ifnull(round(sum(qty*price),2),0) feb_2024_total_amount
,ifnull(round(ifnull(round(sum(qty*price),2),0)/count(distinct orders.order_id),2),0) feb_2024_avg_order_amount
,min(order_date) feb_2024_first_order_date
,max(order_date) feb_2024_last_order_date
from customers left join orders on customers.customer_id = orders.customer_id and month(order_date) = 2 
left join order_items oi on oi.order_id = orders.order_id
group by 1,2
order by 4 desc,1

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务