gpt4 book ai didi

mysql - 案例、子查询和连接

转载 作者:行者123 更新时间:2023-11-29 21:30:50 28 4
gpt4 key购买 nike

我想做的是为所有高于平均时间、平均时间和低于平均时间的游乐设施获取平均tip_portion。所以返回3行。当我运行它时,它显示:

ERROR:  missing FROM-clause entry for table "trip_data"
LINE 11: on trip_data.trip_id= trip_data.trip_id

我已将其更改为 trip_data.trip_id= a.trip_id 它说:

 ERROR:  column a.trip_id does not exist.

我做错了什么。我可以用更简单的方法吗?

select 
AVG(tip / total_fare) as tip_portion, trip_time
from
(
select
avg(trip_time),
case
when avg(trip_time) > 11.05 then 'Above Average'
when avg(trip_time) = 11.05 then 'Average'
when avg(trip_time) < 11.05 then 'Below Average'
end as trip_time_group
from
trip_data
) as a
join
trip_fare ON trip_fare.trip_id = trip_data.trip_id
where
pickup_date <> '2009-12-25'
group by trip_time;

最佳答案

您不会返回任何 trip_id子查询中的列。另外,你应该把 trip_data.trip_id= a.trip_id而不是trip_fare.trip_id= trip_data.trip_id作为trip_data主查询中不存在。

关于mysql - 案例、子查询和连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35281424/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com