Skip to content

Instantly share code, notes, and snippets.

@miklcct
Last active November 24, 2023 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miklcct/c8446380478a36b06de0c327ef2a78a8 to your computer and use it in GitHub Desktop.
Save miklcct/c8446380478a36b06de0c327ef2a78a8 to your computer and use it in GitHub Desktop.
shack attack (National Rail)
select rank() over (order by `first visited`) as sequence, full_station as station, `first visited`, `last visited`, `number of visits`
from (
select case
when station = 'Adlington' then (select 'Adlington (Cheshire)' union select 'Adlington (Lancashire)')
when station = 'Bentley' then case route
when 'South Western Railway' then 'Bentley (Hampshire)'
when 'Northern' then 'Bentley (South Yorkshire)'
else (select 'Bentley (Hampshire)' union select 'Bentley (South Yorkshire)')
end
when station = 'Bramley' then case route
when 'GWR' then 'Bramley (Hampshire)'
when 'Northern' then 'Bramley (West Yorkshire)'
else (select 'Bramley (Hampshire)' union select 'Bramley (West Yorkshire)')
end
when station = 'Brampton' then case route
when 'Greater Anglia' then 'Brampton (Suffolk)'
when 'Northern' then 'Brampton (Cumbria)'
else (select 'Brampton (Suffolk)' union select 'Brampton (Cumbria)')
end
when station = 'Earlswood' then case route
when 'Southern' then 'Earlswood (Surrey)'
when 'Thameslink' then 'Earlswood (Surrey)'
when 'West Midlands Railway' then 'Earlswood (West Midlands)'
else (select 'Earlswood (Surrey)' union select 'Earlswood (West Midlands)')
end
when station = 'Garth' then (select 'Garth (Bridgend)' union select 'Garth (Powys)')
when station = 'Gillingham' then case route
when 'Southeastern' then 'Gillingham (Kent)'
when 'Thameslink' then 'Gillingham (Kent)'
when 'South Western Railway' then 'Gillingham (Dorset)'
else (select 'Gillingham (Kent)' union select 'Gillingham (Dorset)')
end
when station = 'Hope' then case route
when 'Northern' then 'Hope (Derbyshire)'
when 'EMR' then 'Hope (Derbyshire)'
when 'Transport for Wales' then 'Hope (Flintshire)'
else (select 'Hope (Derbyshire)' union select 'Hope (Flintshire)')
end
when station = 'London Road' then case route
when 'Southern' then 'London Road (Brighton)'
when 'South Western Railway' then 'London Road (Guildford)'
else (select 'London Road (Brighton)' union select 'London Road (Guildford)')
end
when station = 'Millbrook' then case route
when 'London Northwestern Railway' then 'Millbrook (Bedfordshire)'
when 'South Western Railway' then 'Millbrook (Hampshire)'
else (select 'Millbrook (Bedfordshire)' union select 'Millbrook (Hampshire)')
end
when station = 'Moreton' then case route
when 'Merseyrail' then 'Moreton (Merseyside)'
when 'South Western Railway' then 'Moreton (Dorset)'
else (select 'Moreton (Merseyside)' union select 'Moreton (Dorset)')
end
when station = 'Newport' then case route
when 'GWR' then 'Newport (South Wales)'
when 'Transport for Wales' then 'Newport (South Wales)'
when 'CrossCountry' then 'Newport (South Wales)'
when 'Greater Anglia' then 'Newport (Essex)'
else (select 'Newport (South Wales)' union select 'Newport (Essex)')
end
when station = 'Queen''s Park' || station = 'Queens Park' then case route
when 'Scotrail' then 'Queens Park (Glasgow)'
when 'London Overground' then 'Queens Park (London)'
else (select 'Queens Park (Glasgow)' union select 'Queens Park (London)')
end
when station = 'Rainham' then case route
when 'Southeastern' then 'Rainham (Kent)'
when 'Thameslink' then 'Rainham (Kent)'
when 'c2c' then 'Rainham (Essex)'
else (select 'Rainham (Kent)' union select 'Rainham (Essex)')
end
when station = 'Reedham' then case route
when 'Southern' then 'Reedham (London)'
when 'Greater Anglia' then 'Reedham (Norfolk)'
else (select 'Reedham (London)' union select 'Reedham (Norfolk)')
end
when station = 'St Margarets' then case route
when 'South Western Railway' then 'St Margarets (London)'
when 'Greater Anglia' then 'St Margarets (Hertfordshire)'
else (select 'St Margarets (London)' union select 'St Margarets (Hertfordshire)')
end
when station = 'Swinton' then (select 'Swinton (Manchester)' union select 'Swinton (South Yorkshire)')
when station = 'Whitchurch' then case route
when 'Transport for Wales' then (select 'Whitchurch (Shropshire)' union select 'Whitchurch (Cardiff)')
when 'South Western Railway' then 'Whitchurch (Hampshire)'
else (select 'Whitchurch (Shropshire)' union select 'Whitchurch (Cardiff)' union select 'Whitchurch (Hampshire)')
end
else station
end as full_station
, convert_tz(min(`time stamp`), @@session.time_zone, 'Europe/London') as `first visited`
, convert_tz(max(`time stamp`), @@session.time_zone, 'Europe/London') as `last visited`
, count(0) as `number of visits`
from (
select route, `boarding place` as station, `boarding time stamp` as `time stamp` from journeys where network = 'National Rail'
union select route, `alighting place`, `alighting time stamp` from journeys where network = 'National Rail'
) as source group by full_station
) source
where full_station not in (
'Aldgate East'
, 'Acton Town'
, 'Bounds Green'
, 'Boston Manor'
, 'Baker Street'
, 'Cockfosters'
, 'Chesham'
, 'Croxley'
, 'East Ham'
, 'East Putney'
, 'Embankment'
, 'Earl''s Court'
, 'Finchley Road'
, 'High Barnet'
, 'Hillingdon'
, 'Holloway Road'
, 'North Acton'
, 'Northwood'
, 'Newbury Park'
, 'Oakwood'
, 'Stanmore'
, 'Turnpike Lane'
, 'Watford'
, 'Wembley Park'
, 'Wimbledon Park'
)
order by `sequence`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment