我创建了一个名为“retail stores”的数据库,并创建了以下表名:“store”、“account”、“order”、“store\u salesperson”和“store\u warehouse\u shipper”。请看下表照片:
我的问题是,如何在不影响表的其他列的情况下,将“hub1”生成或集成为hub列上的一个数据或一个结果?
我的意思是,门店数量、名称、订单数量、总订单量、 Package 箱数量、纬度、经度仍然显示相同的结果,但“hub1”数据只会在hub列中显示一次。
以下是我自学练习的代码:
select (s.id) as '# of stores',
s.name,
(a1.display_name) as hub,
count(o.id) as '# of orders',
sum(total_product_cost) as 'Total Order Size',
sum(o.no_of_boxes) as '# of boxes',
s.point_y as latitude,
s.point_x as longitude
from `order` as o
join store_warehouse_shipper as sws on sws.id = o.associate_id
join store as s on s.id = sws.store_id
join store_salesperson as ss on ss.store_id = s.id
join account as a1 on a1.id=ss.salesperson_account_id
left join store_salesperson as ss1 on ss1.store_id = s.id and
ss1.id>ss.id
where
date(delivered_by) = curdate()
and a1.display_name like '%hub%'
group by s.id, a1.id
order by a1.id ASC
暂无答案!
目前还没有任何答案,快来回答吧!