---
title: "ClickHouse and the MTA Data Challenge"
description: "Loading and cleaning the ~95 million-row NYC MTA subway turnstile dataset (2014–2022) in ClickHouse, using schema inference over S3, a staging table, and an optimized schema with LowCardinality strings, a combined DateTime column, UInt32 counters, sorted line-name arrays and a (station, date_time) ordering key."
url: "https://swe.quest/articles/clickhouse-and-the-mta-data-challenge-dc13e535ba1ed542"
canonical: "https://clickhouse.com/blog/clickhouse-mta-data-challenge-subway-transits-demo"
source: "ClickHouse"
published: "2024-10-24"
difficulty: "medium"
kind: "How-to"
reading_minutes: 16
tags: ["analytics","data-pipelines","sql"]
---

# ClickHouse and the MTA Data Challenge

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2024-10-24, 16 min read, How-to. Original: [https://clickhouse.com/blog/clickhouse-mta-data-challenge-subway-transits-demo](https://clickhouse.com/blog/clickhouse-mta-data-challenge-subway-transits-demo)

## Summary

Loading and cleaning the ~95 million-row NYC MTA subway turnstile dataset (2014–2022) in ClickHouse, using schema inference over S3, a staging table, and an optimized schema with LowCardinality strings, a combined DateTime column, UInt32 counters, sorted line-name arrays and a (station, date\_time) ordering key. Because entry/exit counters are cumulative odometer-style readings that reset, count down and overflow, window functions partitioned by turnstile (ca, unit, scp) compute per-period deltas and discard negative or implausible values above a per-hour threshold. The steps are reproducible with clickhouse-local, and the cleaned data is published in the ClickHouse SQL playground.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Data pipelines](https://swe.quest/tags/data-pipelines.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL window functions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- columnar OLAP databases ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))
- ClickHouse MergeTree basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, MTA Open Data Challenge, clickhouse-local, MergeTree, LowCardinality, s3Cluster

## Related posts

- [ClickPy at 2 Trillion rows: Scaling ingestion and fixing the past](https://swe.quest/articles/clickpy-at-2-trillion-rows-scaling-ingestion-and-fixing-the-past-d834572321743679.md): ClickHouse · 2026-01-21 · Medium · 7 min read · Data pipelines, Analytics & OLAP, Schema migrations
  ClickPy, ClickHouse's free PyPI download analytics service, now holds over 2.2 trillion rows, and its cron-based ingestion script was replaced with ClickPipes without downtime.
- [How Chartmetric uses ClickHouse to turn artist data into music intelligence](https://swe.quest/articles/how-chartmetric-uses-clickhouse-to-turn-artist-data-into-music-intelligence-ce4a9132c749d911.md): ClickHouse · 2025-05-21 · Medium · 7 min read · Analytics & OLAP, Databases, PostgreSQL, Observability, Cost optimization
  Chartmetric moved its heaviest time-series and relational workloads off Postgres RDS and Snowflake.
- [Replacing the HDB: ClickHouse for historical ticker data](https://swe.quest/articles/replacing-the-hdb-clickhouse-for-historical-ticker-data-cd7a8f768807547b.md): ClickHouse · 2026-07-15 · Medium · 19 min read · Analytics & OLAP, SQL, Databases, Performance engineering
  ClickHouse can serve as the historical tier (HDB) of a market data system, a low-risk place to adopt a new database.
- [What Replo learned optimizing 100+ billion events in ClickHouse](https://swe.quest/articles/what-replo-learned-optimizing-100-billion-events-in-clickhouse-4b7228146ec28a74.md): ClickHouse · 2026-03-09 · Medium · 7 min read · Analytics & OLAP, Databases, Performance engineering, Scaling
  Replo's in-product analytics for Shopify merchants ingests 3,000-5,000 events per second into ClickHouse and analyzes 100+ billion events, but reaching that point took several data-model resets.
- [How the D. E. Shaw group powers high-cardinality observability at scale with ClickHouse](https://swe.quest/articles/how-the-d-e-shaw-group-powers-high-cardinality-observability-at-scale-with-b74a9887c2072ab0.md): ClickHouse · 2026-05-15 · Medium · 7 min read · Observability, Analytics & OLAP, Scaling, Capacity planning
  The D. E. Shaw group moved per-task resource metrics from its HPC grid, millions of high-cardinality time series keyed by unique task IDs, from an InfluxDB-protocol time-series platform to ClickHouse.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
