SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Rising Temperature

/challenges/rising-temperature

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog
SQL Challenges/Rising Temperature
Challenge DetailMediumReviewed 2026-04-20

Rising Temperature

Find all dates' Ids with higher temperatures compared to its previous dates (yesterday).

Date LogicWindow FunctionsJoin

This challenge now meets the current minimum standard for sitemap inclusion and independent indexing.

2025-12-16Medium

Rising Temperature

Find all dates' Ids with higher temperatures compared to its previous dates (yesterday).

Available Tables:
SQL Editor
Loading...

What This Challenge Is Testing

Day-over-day comparisons show up constantly in analytics work: revenue growth, retention movement, traffic spikes, and sensor changes all use the same pattern. This problem teaches the underlying idea of joining or windowing a time series against its previous observation.

Topic Tags

DatesWindow FunctionsAnalytics

Schema At A Glance

weather
idrecordDatetemperature

Solution Approaches

01

Self join on a one-day offset

SELECT
  w1.id
FROM weather w1
JOIN weather w2
  ON DATE(w1.recordDate) = DATE(w2.recordDate, '+1 day')
WHERE w1.temperature > w2.temperature

This approach pairs each row with the row from exactly one day earlier, then keeps only the rows where the current temperature is higher. It is easy to reason about because the previous day is modeled directly as another copy of the same table.

02

LAG over the ordered dates

WITH temps AS (
  SELECT
    id,
    recordDate,
    temperature,
    LAG(recordDate) OVER (ORDER BY recordDate) AS prev_date,
    LAG(temperature) OVER (ORDER BY recordDate) AS prev_temp
  FROM weather
)
SELECT
  id
FROM temps
WHERE DATE(prev_date) = DATE(recordDate, '-1 day')
  AND temperature > prev_temp

The window-function version is useful when you already need ordered row-to-row comparisons. It is more scalable conceptually because you can extend it to growth rates, rolling deltas, and longer sequences without adding more self joins.

Common Pitfalls

Do not assume the previous row is always yesterday unless you check the date gap explicitly. If the table skips dates, comparing to the previous row without verifying the one-day difference will produce false positives.

Frequently Asked Questions

Why not just compare IDs instead of dates?

IDs often increase with insertion order, not calendar order. The business condition is about yesterday, so the join must be based on date arithmetic rather than assuming consecutive IDs mean consecutive days.

When is the window-function version preferable?

Use LAG when you are doing a broader time-series analysis pipeline and already need ordered row comparisons. It keeps the logic in one ordered pass and is easier to extend to percent change or streak detection.

Concept Guides

Use these guides when you want the fuller explanation behind the SQL pattern this challenge is testing.

Time Series Analysis with SQL: Trends, Growth, and Moving Averages

Turn raw timestamps into business insights. Learn how to calculate Month-over-Month growth and smooth out noisy data with 7-day moving averages.

Mastering SQL Date and Time Functions

Stop struggling with dates in SQL. Learn how to handle current time, date arithmetic, formatting, and time differences using standard SQL and SQLite syntax.

Mastering SQL Self Joins: A Complete Guide with Interactive Examples

Stop being confused by joins on the same table. Learn how to master Self Joins for organizational hierarchies, sequential data comparison, and more.

Topic Hubs

If this problem exposed a deeper weakness, use a topic hub to move through a curated cluster instead of random article hopping.

Analytics

Analytics SQL and business metrics

A practical cluster for cohorts, funnels, customer value, and the kinds of reporting questions teams actually ask every week.

Advanced SQL

Advanced query patterns

Use this path when you are moving beyond beginner SELECT queries into CTEs, window functions, and conditional logic.

Practice Path

If you want the rotating practice flow, open this same question from the daily stream. If you want interview-style packaging, continue into the interview pool after this rep.

Back to ChallengesOpen In DailyBrowse Interviews

Related Challenges

Rank ScoresMedium

Assign tied scores the same rank while keeping the next rank consecutive with no gaps.

Trips and UsersHard

Compute daily cancellation rate after excluding any trip where either the client or driver is banned.

Product Price at a Given DateMedium

Reconstruct each product’s price as of a snapshot date, including products that had not changed yet and still use the default price.

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed