with taxis as (
select
sum(total_amount) as total,
pickup_datetime :: date as date
from
nyc_yellow_taxi_0601_0615_2016
group by
pickup_datetime :: date
order by
pickup_datetime :: date asc
)
select
date,
total,
avg(total) over (
order by
date rows between 2 preceding
and current row
)
from
taxis
with taxis as (
select
sum(total_amount) as total,
passenger_count,
pickup_datetime :: date as date
from
nyc_yellow_taxi_0601_0615_2016
group by
pickup_datetime :: date,
passenger_count
order by
pickup_datetime :: date asc,
passenger_count desc
)
select
date,
total,
passenger_count,
sum(total) over (
partition by passenger_count
order by
date rows between 2 preceding
and current row
)
from
taxis
select
avg(tip_amount / total_amount),
extract(
hour
from
pickup_datetime
) as hour_of_day
from
nyc_yellow_taxi_0601_0615_2016
where
pickup_datetime :: date = '2016-06-15'
-- since we can't divide by 0 we will remove all amounts
-- that equal 0
and total_amount > 0
group by
extract(
hour
from
pickup_datetime
)
order by
extract(
hour
from
pickup_datetime
) asc
with taxis as (
select
avg(tip_amount / total_amount) as tip_percentage,
date_trunc('hour', pickup_datetime) as day_hour
from
nyc_yellow_taxi_0601_0615_2016
where
total_amount > 5
group by
date_trunc('hour', pickup_datetime)
)
select
day_hour,
tip_percentage,
avg(tip_percentage) over (
order by
day_hour asc rows between 5 preceding
and current row
) as moving_average
from
taxis
with taxis as (
select
sum(total_amount) as total,
passenger_count,
pickup_datetime :: date as date
from
nyc_yellow_taxi_0601_0615_2016
group by
pickup_datetime :: date,
passenger_count
order by
pickup_datetime :: date asc,
passenger_count desc
)
select
date,
total,
passenger_count,
sum(total) over (
partition by passenger_count
order by
date
)
from
taxis
select
row_number() over(partition by pickup_datetime) as row_no,
ogc_fid,
pickup_datetime
from
nyc_yellow_taxi_0601_0615_2016
limit
5 offset 100000 -- using offset since the first part of the datasets has all passenger counts as 0
with taxis as (
select
sum(total_amount) as total,
passenger_count,
pickup_datetime :: date as date
from
nyc_yellow_taxi_0601_0615_2016
group by
pickup_datetime :: date,
passenger_count
order by
pickup_datetime :: date asc,
passenger_count desc
)
select
date,
total,
passenger_count,
total - lag(total, 1) over (
partition by passenger_count
order by
date
)
from
taxis