PostgreSQL Practice Problems

These PostgreSQL practice problems cover much more than basic SELECT queries. Work through joins, aggregations, window functions, table definitions, JSON data, and query optimization. You can also practice PostgreSQL-specific features where a problem calls for them. Every query runs in a real PostgreSQL database and is automatically checked using hidden data. Problems: 1,003, free: 240.

Problems in this set: 1,003, free: 240

Start with a free problem

PostgreSQL problems

FiltersEasy · Free

Problems found: 237

Reset filters
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Bands That Departed from Vladivostok

    Regional news outlets in the Russian Far East want to know which bands departed on tour from Vladivostok. Return their names without duplicates.

  • EasyFree
    PostgreSQL · MySQL

    Trips Departing from Paris

    The tour logistics team is mapping out trips departing from Paris, including each destination and travel time.

  • EasyFree
    PostgreSQL · ClickHouse

    Count Rows After DISTINCT on a GROUP BY Result

    An Avito interview question tests whether candidates understand that applying DISTINCT to an already grouped result often changes nothing.

    Avito
  • EasyFree
    PostgreSQL · ClickHouse

    Daily Transaction Volume by Banking Product

    Gazprombank is building a daily transaction volume report for its corporate banking products. Each operation has an associated client, product category, and amount in rubles.

    Gazprombank
  • EasyFree
    PostgreSQL · ClickHouse

    Active Contract Version on March 15, 2024

    Rosbank's DDS layer stores contract history using SCD2. Each record version is valid over a right-open interval stored in the valid column, meaning the lower bound is inclusive and the upper bound is…

    Rosbank
  • EasyFree
    PostgreSQL · ClickHouse

    OTP Code Category Indicator

    Otkritie Bank is building a risk score based on the type of operation confirmed by an OTP code.

    Otkritie Bank
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    All Registered Fans

    A tour promoter needs a complete list of registered fans to send invitations to a private performance. Return the names of all fans in the database.

  • EasyFree
    PostgreSQL · ClickHouse

    Category with the Most OTP Entries

    Otkritie Bank is analyzing two-factor authentication flows to find where customers enter OTP codes most often. This will help improve UX and assess the load on the SMS gateway.

    Otkritie Bank
  • EasyFree
    PostgreSQL · ClickHouse

    Active Students on April 15, 2024

    Skypro uses a daily dashboard to show how many students are actively studying. Each course enrollment has an access period: the start date is inclusive, and the end date is exclusive.

    Skypro
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Most Active Message Senders in August 2022

    Microsoft Teams wants to identify its most active users: those who sent the most messages in August 2022. Find the top two senders and return sender_id and message_count.

    Microsoft
  • EasyFree
    PostgreSQL · ClickHouse

    Skypro Revenue by Course for March 2024

    Skypro's finance team is closing out the last full calendar month and wants revenue totals for each course. The current date is fixed at 2024-04-15, so the last full month is March 2024.

    Skypro
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Club Concerts

    The band's management wants to know how often the tour features club shows because that affects the marketing budget. Count all concerts held at venues of type Club.

What you will practice

  • Write queries and joins using PostgreSQL syntax
  • Apply FILTER and DISTINCT ON where they fit
  • Work with JSONB and cast values using ::
  • Create and alter database tables with DDL
  • Read execution plans using EXPLAIN ANALYZE

Common mistakes

  1. 1. Using DISTINCT ON without the right sorting

    DISTINCT ON keeps one row for each distinct combination of expressions, but ORDER BY determines which row is selected. Without suitable sorting, you may get an arbitrary record instead of the latest or highest-valued one. Define which row should win within each group.

  2. 2. Assuming every type cast is safe

    PostgreSQL supports convenient casts using ::, but casting cannot turn invalid text into a valid number or date. An unexpected value may cause the query to fail. Check the source data type and consider which input formats are valid before applying a conversion.

  3. 3. Treating JSONB as plain text

    JSONB stores structured JSON data rather than an ordinary text string. When extracting nested values, it matters whether you need a JSON value or its text representation. Check the returned type and consider what should happen when a key or nested field is missing.

  4. 4. Assuming EXPLAIN ANALYZE only describes a query

    EXPLAIN ANALYZE actually executes the statement and collects runtime statistics. This matters especially for statements that modify data. When reading the output, compare estimated and actual row counts as well as execution times instead of focusing only on operation names.

Theory and courses

Frequently asked questions

Do these exercises run on a real PostgreSQL database?

Yes. Your queries execute in PostgreSQL rather than a simulated SQL environment. Their results are automatically compared with expected results using hidden data. This allows you to practice standard SQL concepts alongside PostgreSQL-specific syntax and behavior when the problem requires it.

Which PostgreSQL exercises are free?

Free PostgreSQL problems: 240. After signing in, the free plan lets you solve up to 3 new problems each day. Premium problems appear in the catalog but require a subscription. Problems also include hints and an AI mentor.

Are these PostgreSQL problems only about SELECT?

No. The collection covers SQL topics ranging from basic selections and joins to window functions, DDL, JSON, and query optimization. You can start with straightforward queries and move on to more specialized PostgreSQL features as you become comfortable with the fundamentals.

What are FILTER and DISTINCT ON used for?

FILTER applies a condition to an individual aggregate calculation, making it useful when calculating different metrics for the same groups. DISTINCT ON selects one row per distinct set of expressions. They solve different problems, and DISTINCT ON requires careful ordering to select the intended row.

What can EXPLAIN ANALYZE tell me?

It shows how PostgreSQL executed a statement, including actual row counts and timing information for plan operations. Comparing those figures with estimates can help identify expensive steps. Remember that EXPLAIN ANALYZE executes the statement, so use care with operations that change data.