如何在postgresql中选择最近30天内的日期?

wecizke3  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(279)

sql表有出租车司机的数据,列是:

id  integer
client_id   integer (Foreign keyed to events.rider_id)
driver_id   integer
city_id integer (Foreign keyed to cities.city_id)
client_rating   integer
driver_rating   integer
predicted_eta   integer
actual_eta  integer
first_completed_date Timestamp ,
status  Enum(‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’)

字符串
如何计算过去30天内所有已完成的行程的实际预计到达时间与预计到达时间之间的第90百分位数差异?

select

  percentile_cont(0.90) within group (order by actual_eta-predicted_eta) as percentile_90_diff

from trips t where status='completed'

and first_completed_date > (first_completed_date - INTERVAL '30 DAY')::DATE


我关心的是最后一部分- first_completed_date > -在过去的30天内。从first_completed_date开始计算过去的30天是否正确?

uurv41yg

uurv41yg1#

您将“first_completed_date”与其本身进行了比较,但是,需要将其与当前日期减去30天进行比较

first_completed_date > NOW() - INTERVAL '30 DAY';

字符串

相关问题