题解 | 查询出每个运输方式在不同城市的平均运输时长以及总运输费用

查询出每个运输方式在不同城市的平均运输时长以及总运输费用

https://www.nowcoder.com/practice/673bf7b17e7c4962bcde889980eec872

with t1 as
(select transport_detail.transport_id,transport_name,destination_city,round(avg(datediff(delivery_date , order_date )),2) average_transport_duration
from transport_detail join order_info on transport_detail.transport_id = order_info.transport_id
group by transport_detail.transport_id,transport_name,destination_city),
t2 as 
(select transport_detail.transport_id,destination_city,round(sum(total_cost ),2) total_transport_cost
from transport_detail join order_info on transport_detail.transport_id =order_info.transport_id join cost_data on order_info.order_id =cost_data.order_id 
group by transport_detail.transport_id,destination_city)

select  t1.destination_city,t1.transport_name,average_transport_duration,total_transport_cost
from t1,t2
where t1.transport_id=t2.transport_id and t1.destination_city=t2.destination_city
order by t1.destination_city,t1.transport_name

全部评论

相关推荐

25届的可以参加26届秋招吗?身为25届的,现在辞职很尴尬,经验不足一年(正式工)又正在秋招,现在找工作有点尬住了
程序员小白条:哪有一年啊,才几个月吧,参加26秋招不存在的,社招了啊,你正式工都交过社保了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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