Skip to content

Practice Reformat Department Table

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1179
LeetCode Problem

Reformat Department Table

Problem Statement

Tables: Department(id INT, revenue INT, month VARCHAR). Department has key (id, month). month is one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec. Return one row per id with Jan_Revenue through Dec_Revenue as separate columns. A missing month has null revenue, not zero. Output order is unrestricted.

Source: Reformat Department Table on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Department table: +------+---------+-------+ | id   | revenue | month | +------+---------+-------+ | 1    | 8000    | Jan   | | 2    | 9000    | Jan   | | 3    | 10000   | Feb   | | 1    | 7000    | Feb   | | 1    | 6000    | Mar   | +------+---------+-------+
Output
+------+-------------+-------------+-------------+-----+-------------+ | id   | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue | +------+-------------+-------------+-------------+-----+-------------+ | 1    | 8000        | 7000        | 6000        | ... | null        | | 2    | 9000        | null        | null        | ... | null        | | 3    | null        | 10000       | null        | ... | null        | +------+-------------+-------------+-------------+-----+-------------+

Related LeetCode Problems

Practice more problems similar to Reformat Department Table.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.