gpt4 book ai didi

sql - PostgreSQL-错误 : column does not exist SQL state: 42703

转载 作者:行者123 更新时间:2023-11-29 11:41:26 25 4
gpt4 key购买 nike

我正在尝试进行同期群分析,并根据承租人的第一个租赁年(= 承租人首次出租的年份)比较平均租金数。基本上,我在问一个问题:与第一年为 2015 年的租房者相比,我们是否保留了第一年租房为 2013 年的租房者?

这是我的代码:

SELECT renter_id, 
Min(Date_part('year', created_at)) AS first_rental_year,
( Count(trip_finish) ) AS number_of_trips
FROM bookings
WHERE state IN ( 'approved', 'aboard', 'ashore', 'concluded', 'disputed' )
AND first_rental_year = 2013
GROUP BY 1
ORDER BY 1;

我得到的错误信息是:

ERROR:  column "first_rental_year" does not exist
LINE 6: ... 'aboard', 'ashore', 'concluded', 'disputed') AND first_rent...
^

********** Error **********

ERROR: column "first_rental_year" does not exist
SQL state: 42703
Character: 208

非常感谢任何帮助。

最佳答案

SELECT renter_id,
Count(trip_finish) AS number_of_trips
FROM (
SELECT renter_id,
trip_finish,
Min(Date_part('year', created_at)) AS first_rental_year
FROM bookings
WHERE state IN ( 'approved', 'aboard', 'ashore', 'concluded', 'disputed' )
) T
WHERE first_rental_year = 2013
GROUP BY renter_id
ORDER BY renter_id ;

关于sql - PostgreSQL-错误 : column does not exist SQL state: 42703,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37418028/

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