有人可以帮助我吗? 我在 BigQuery 上,我想要一个如下表;
结果 | 订单计数 |
---|---|
低 | 215 |
中 | 379 |
高 | 90 |
with base_table as (
select order_id, o.customer_id, count( order_id) as count_of_order
from `orders_table` o
join `customers_table` c on o.customer_id = c.customer_id
group by 1,2
)
select
case
when base_table.count_of_order < 500 then "low"
when base_table.count_of_order between 501 and 1000 then "mid"
when base_table.count_of_order > 1000 then "high"
else null
end as result,
count_of_order
from base_table
group by 1,2
只需在
sum
上添加 count_of_order
即可?
with base_table as (
select order_id, o.customer_id, count( order_id) as count_of_order
from `orders_table` o
join `customers_table` c on o.customer_id = c.customer_id
group by 1,2
)
select
case
when base_table.count_of_order < 500 then "low"
when base_table.count_of_order between 501 and 1000 then "mid"
when base_table.count_of_order > 1000 then "high"
else null
end as result,
sum(count_of_order) AS count_of_order
from base_table
group by 1