Each Client's Latest Purchased Device
The CRM team is preparing an upsell campaign for clients who recently bought devices.
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 problemProblems found: 763
Reset filtersThe CRM team is preparing an upsell campaign for clients who recently bought devices.
A library wants to identify popular works. Find works that have been checked out more than 5 times. Return title and checkout_count. Sort the result by checkout count in descending order.
The CRM team wants to know how many days it takes new users to make their first purchase after signing up.
The finance team needs a monthly breakdown of bookings. For each calendar month with at least one booking based on the booking start date start_date, return the year as year, the month as month, and…
MTS is analyzing which dates have a high number of iPhone owners recorded in its device database.
The finance team is looking at the range of purchase amounts, focusing on the extremes. Among purchase events (kind = 'purchase') in a_events, find the minimum and maximum amount.
A school administrator wants a new seating chart in which students swap seats in adjacent pairs. Return id and student to show the seating arrangement after the swaps.
The product team wants to find users who showed interest in buying something but never completed a purchase.
The growth team wants to know which email providers passengers use to better target email campaigns. Group passenger email addresses by domain, meaning everything after the @ symbol.
A librarian is reviewing the catalog for works nobody has borrowed. Find works that have never been checked out, meaning they have no records in checkouts. Return all columns for those works.
The product analytics team is studying purchasing activity using events in a_events. The event type is stored in kind and can be visit, cart, or purchase. Count each user's purchase events.
The sales team is looking for accounts belonging to companies whose names contain the substring SBER. For all such companies, return the account_id and account_type of their accounts.
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.
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.
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.
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.
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.
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.
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.
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.
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.