Find Days Warmer Than Their Actual Previous Calendar Day

Quick Overview

Return the id of each Weather row whose temperature exceeds the temperature on the immediately preceding calendar date. A previous stored row separated by a date gap is not yesterday. Result ordering is unrestricted.

Find Days Warmer Than Their Actual Previous Calendar Day

Company: Amazon

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

### Problem Return the id of each Weather row whose temperature exceeds the temperature on the immediately preceding calendar date. A previous stored row separated by a date gap is not yesterday. Result ordering is unrestricted. ### Tables Table: `Weather` ```text +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | recordDate | date | | temperature | int | +---------------+---------+ id is the column with unique values for this table. There are no different rows with the same recordDate. This table contains information about the temperature on a certain day. ``` ### Example ```text Weather (id,recordDate,temperature): (4,2021-02-01,8), (9,2021-02-02,12), (10,2021-02-04,20), (11,2021-02-05,20) Output (id): (9) ``` ### What a Strong Answer Covers - Use calendar dates, including gaps between stored observations. - Keep only strictly warmer observations and return the requested ID. - Explain the handling of equal temperatures and missing dates. ### Follow-up Questions - What changes if the comparison is with the most recent recorded date? - What result should an example spanning December 31 and January 1 produce?

Overview: Return the id of each Weather row whose temperature exceeds the temperature on the immediately preceding calendar date. A previous stored row separated by a date gap is not yesterday. Result ordering is unrestricted.

Amazon logo
Amazon
easySoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return the id of each Weather row whose temperature exceeds the temperature on the immediately preceding calendar date. A previous stored row separated by a date gap is not yesterday. Result ordering is unrestricted.

Tables

Table: Weather

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| id            | int     |
| recordDate    | date    |
| temperature   | int     |
+---------------+---------+
id is the column with unique values for this table.
There are no different rows with the same recordDate.
This table contains information about the temperature on a certain day.

Example

Weather (id,recordDate,temperature): (4,2021-02-01,8), (9,2021-02-02,12), (10,2021-02-04,20), (11,2021-02-05,20)
Output (id): (9)

What a Strong Answer Covers Guidance

  • Use calendar dates, including gaps between stored observations.
  • Keep only strictly warmer observations and return the requested ID.
  • Explain the handling of equal temperatures and missing dates.

Follow-up Questions Guidance

  • What changes if the comparison is with the most recent recorded date?
  • What result should an example spanning December 31 and January 1 produce?