我只想找到每个仓库处理的订单总数。但是查询和结果没有意义

i just want to find the total number of orders handled by each warehouse . But the query and results doesn't make sense

提问人:jason 提问时间:11/15/2023 更新时间:11/17/2023 访问量:38


答:

-1赞 rtenha 11/17/2023 #1

您的子查询与查询的其余部分不相关,这就是为什么每个仓库都获得相同编号的原因。您正在计算数据集中的订单总数 (9999),然后将该总数连接到每个仓库。

请考虑以下几点:

select
  warehouse.warehouse_alias,
  count(orders.order_id) as order_count
from orders
left join warehouse on orders.warehouse_id = warehouse.warehouse_id
group by 1