Apples & Oranges

4pts
Fruit Co

Problem Statement

You are given a sales table for a fruit stand. Each row represents the number of a specific fruit sold on a given day.

Write an SQL query to report the difference between the number of apples and oranges sold each day.

Rules:

  • Return the result as (apples_sold - oranges_sold).
  • Output columns: sale_date, diff.
  • Results must be sorted by sale_date in ascending order.
Tests your understanding of
Pivoting, Aggregation and Conditional Logic

Input Tables

Sales
sale_date(DATE)fruit(VARCHAR)sold_count(INTEGER)
2026-02-01apples10
2026-02-01oranges8
2026-02-02apples15
2026-02-02oranges20
2026-02-03apples20
2026-02-03oranges0
Inventory
fruit(VARCHAR)stock_remaining(INTEGER)
apples100
oranges50
Fruit_Prices
fruit(VARCHAR)price_per_unit(DECIMAL)
apples0.5
oranges0.6

Expected Output

sale_date(DATE)diff(INTEGER)
2026-02-012
2026-02-02-5
2026-02-0320

Tags

MediumPivotingAggregationConditional Logic
15-20 min
72%

Hints