Skip to content

Instantly share code, notes, and snippets.

@nkkarthik
Created November 16, 2019 04:27
Show Gist options
  • Save nkkarthik/8964f80a944ab7ca5f1c4711cbd432e9 to your computer and use it in GitHub Desktop.
Save nkkarthik/8964f80a944ab7ca5f1c4711cbd432e9 to your computer and use it in GitHub Desktop.
select ts,
seats,
sum(seats) over(order by rownum) as usage
from (
select
row_number() over(order by '1') as rownum,
to_timestamp(columns[0], 'yyyy-MM-dd HH:mm:ss Z z') as ts,
case
when columns[1] = 'out' then cast(columns[3] as int)
when columns[1] = 'in' then -1 * cast(columns[3] as int)
else 0
end as seats
from dfs.tmp.`test1.csv`
where columns[1] = 'out' or columns[1] = 'in'
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment