问题描述
-每月有多少客户下订单?
表格:客户
所需的输出:
with abc as (select concat(year(order_date),'/',month(order_date)) "date",customer_id
from customer
group by 1,2
order by 1)
select date,count(*) "customers_who_ordered"
from abc
group by 1;
我不需要子查询或CTE查询。有没有办法可以在单个查询中获得相同的输出?
解决方法
您可以尝试以下-
select concat(year(order_date),'/',month(order_date)) "date",count(distinct customer_id)
from customer
group by concat(year(order_date),month(order_date))