SQL Practice for Beginners

New to SQL? Start with beginner-friendly practice problems covering SELECT, filtering, sorting, grouping, and simple joins. Every exercise in this collection is rated Easy, and all are free. Write your queries and run them against a real database, with automatic result checking on hidden data. Problems in this collection: 289, free: 289.

Problems in this set: 289, free: 289

Start with a free problem

Easy problems to start with

  • EasyFree
    ClickHouse

    Median and average duration by device

    From the sessions table, for each device compute the median of duration_sec (median_duration) and the average duration rounded to 2 decimals (avg_duration).

  • EasyFree
    ClickHouse

    Sessions per device

    From the sessions table, count how many sessions each device has. Group by device and return columns device and sessions (the row count of sessions). Sort by device ascending.

  • EasyFree
    ClickHouse

    Bounce rate per device

    From the sessions table, compute each device's bounce rate: the ratio of sessions with bounced = 1 to the total number of sessions.

  • EasyFree
    ClickHouse

    Bounced vs engaged sessions per device

    From the sessions table, for each device count two metrics: bounced_sessions — sessions with bounced = 1, and engaged_sessions — sessions with bounced = 0.

  • EasyFree
    ClickHouse

    Distinct countries per device

    From sessions(device, country), count the number of distinct countries per device. Output columns device and countries. Order by countries descending, then by device ascending.

  • EasyFree
    ClickHouse

    Number of distinct pages per user

    From sessions(user_id, page), count the number of distinct pages each user_id visited. Output columns user_id and distinct_pages. Order by distinct_pages descending, then by user_id ascending.

  • EasyFree
    ClickHouse

    Row counts by status code (ClickHouse)

    From table logs, count the number of rows cnt for each status_code. Output columns status_code, cnt. Order by status_code.

  • EasyFree
    ClickHouse

    Average latency per service

    From logs(service, latency_ms) compute the mean request latency for each service. Return columns service and avg_latency (the average of latency_ms rounded to 2 decimals). Order by service ascending.

  • EasyFree
    ClickHouse

    Min and max latency per service

    From logs(service, latency_ms) find the smallest and largest latency for each service. Return columns service, min_latency (min latency_ms) and max_latency (max latency_ms).

  • EasyFree
    ClickHouse

    Latency stats per log level

    From logs(level, latency_ms) compute the average and maximum latency for each log level. Return columns level, avg_latency (average latency_ms rounded to 2 decimals) and max_latency (max latency_ms).

  • EasyFree
    ClickHouse

    Success rate by payment method (ClickHouse)

    In payments, for each method compute the total number of transactions total = count(), the number of successful ones successes = rows with status = 'success', and success_rate = successes / total…

  • EasyFree
    ClickHouse

    Successful revenue by method (ClickHouse)

    In payments, for each method compute revenue — the sum of amount over rows with status = 'success' only (failed/refunded are excluded). Use sumIf. Order by method. Columns: method, revenue.

What you will practice

  • Turn simple questions into SELECT statements
  • Filter rows using one or more conditions
  • Sort results and limit the number of returned records
  • Calculate basic aggregates and group related rows
  • Connect tables using matching keys

Common mistakes

  1. 1. Selecting more columns than requested

    It is tempting to use SELECT with every column, even when a problem asks for only a name and date. The returned rows might look correct, but the output structure will not match the requirement. Check the requested column names, their order, and whether any extra columns appear.

  2. 2. Confusing text values with column names

    SQL treats column identifiers and text values differently. If you forget quotes around a string literal, the database may interpret it as a column name and return an error. When debugging, identify which parts of the expression refer to fields and which represent values.

  3. 3. Assuming rows have a natural order

    A table may appear to return records in a consistent sequence, but SQL does not guarantee that order without ORDER BY. If a task asks for the earliest records or highest prices, specify the sorting rule explicitly. Check both ends of the result.

  4. 4. Testing a filter with only one case

    A WHERE condition using AND and OR may work for one row but fail for others. Test records that satisfy all conditions, only one condition, or none of them. Parentheses make the intended logic clearer and reduce mistakes caused by operator precedence.

Theory and courses

Frequently asked questions

Are all beginner SQL exercises free?

Yes. This collection contains only Easy-level problems, and every one is free. Total problems: 289, free: 289. After signing in, the free plan allows up to 3 new problems per day. Free access does not remove that daily limit.

Can I see the solution if my query is wrong?

Reference solutions are not published. You submit your own SQL, and the trainer checks its output against expected results using hidden data. If your query does not pass, revisit the requirements and use the available hints or AI mentor for guidance.

Where should I start if I have never written SQL?

Begin by selecting columns from a single table. Then practice filtering with WHERE and sorting with ORDER BY. Once those steps make sense, try grouping records and joining tables. The Easy collection covers different SQL topics, so you can build up gradually.

Why are there JOIN exercises for beginners?

Difficulty depends on more than the SQL feature being used. A straightforward join between two tables with a clear matching key can be an Easy problem. If JOIN is unfamiliar, practice single-table queries first and return to table relationships afterward.

What if my SQL runs but fails the check?

A query can be valid SQL and still produce the wrong answer. Check the requested columns, filtering conditions, grouping, and ordering. Think about duplicates, NULL values, and edge cases. Since checking uses hidden data, your logic needs to work beyond the visible example.