martin/demo/db/initdb/03.sql

11 lines
380 B
MySQL
Raw Normal View History

2018-10-25 13:08:07 +03:00
drop table if exists trips_by_hour;
2018-10-24 14:00:45 +03:00
create table trips_by_hour as
select
2018-10-25 13:08:07 +03:00
pulocationid,
count(*) as trips_count,
round(avg(total_amount)) trips_price,
round(avg(extract(epoch from (dropoff_datetime - pickup_datetime)) / 60))::INTEGER trips_duration,
date_trunc('hour', pickup_datetime) as pickup_datetime
2018-10-24 14:00:45 +03:00
from trips
2018-10-25 13:08:07 +03:00
group by pulocationid, date_trunc('hour', pickup_datetime);