QA Interview Hub · Knowledge base · Quizzes · Українська

All topics

SQL interview questions

129 questions on SQL, from the basics to the hard ones. Answers and explanations are in the quiz and the knowledge base.

By level: Junior QA interview questions · Middle QA interview questions · Senior QA interview questions

Database basics

  1. A student can enrol in many courses and a course has many students. How is this stored in a relational database? Junior
  2. How does a UNIQUE constraint differ from a PRIMARY KEY in PostgreSQL? Junior
  3. What does this query return in PostgreSQL? Middle
    SELECT (NULL AND FALSE) AS a, (NULL OR TRUE) AS b;
  4. What does this query return in PostgreSQL and what does it mean for checking money amounts stored in double precision columns? Middle
    SELECT 0.1::double precision + 0.2::double precision = 0.3::double precision;
  5. What happens on the second INSERT? Junior
    CREATE TABLE enrollments (
      student_id int,
      course_id int,
      PRIMARY KEY (student_id, course_id)
    );
    INSERT INTO enrollments VALUES (1, 10);
    INSERT INTO enrollments VALUES (1, 10);
  6. The orders table repeats the customer name and email in every row. What is the problem and what to do? Junior
  7. How is a one-to-one relationship (a user and their profile) stored in a relational database? Junior
  8. Which group of SQL commands does GRANT SELECT ON orders TO qa_reader belong to? Junior
  9. How many rows does the query count? The values of x are 1, NULL, 3. Middle
    SELECT COUNT(*)
    FROM (VALUES (1), (NULL), (3)) AS t(x)
    WHERE x <> 1;
  10. What does the query return in PostgreSQL? Junior
    SELECT 7 / 2   AS a,
           7 / 2.0 AS b,
           7 % 2   AS c;
  11. What does the last query return? The foreign key is declared with ON DELETE CASCADE. Middle
    CREATE TABLE users (id int PRIMARY KEY);
    CREATE TABLE accounts (
      id      int PRIMARY KEY,
      user_id int REFERENCES users (id)
              ON DELETE CASCADE
    );
    INSERT INTO users VALUES (1);
    INSERT INTO accounts VALUES (10, 1), (11, 1);
    DELETE FROM users WHERE id = 1;
    SELECT COUNT(*) FROM accounts;
  12. Which PostgreSQL type fits the moment of an event seen by users in different time zones? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

SELECT and filtering

  1. How many rows will the query return if the table has rows with deleted_at = NULL? Middle
    SELECT * FROM users WHERE deleted_at = NULL;
  2. In what order is a SELECT query logically executed? Middle
  3. How is UNION different from UNION ALL? Middle
  4. What will LIMIT 10 OFFSET 20 return? Junior
  5. What does COALESCE(phone, email, 'n/a') return? Junior
  6. How do you search emails case-insensitively in PostgreSQL? Junior
  7. In PostgreSQL, how do you select orders from the last 7 days? Middle
  8. How do you output the status "large" for amounts over 10,000 and "regular" for the rest? Middle
  9. What is AVG(rating) for the values 5, NULL, 3? Middle
  10. How do you count the number of unique customers who paid? Middle
  11. The created_at column is of type timestamp. Which orders does this query not count? Middle
    SELECT count(*) FROM orders
    WHERE created_at BETWEEN '2026-09-01' AND '2026-09-30';
  12. In PostgreSQL you must find promo codes that contain a literal %. Which filter is correct (standard_conforming_strings = on, default ESCAPE)? Middle
  13. Which values does the query return? The values of name are a_b, axb, ab. Junior
    SELECT name
    FROM (VALUES ('a_b'), ('axb'), ('ab')) AS t(name)
    WHERE name LIKE 'a_b';
  14. Which values of x does the query return? The values of x are 1, 5, 10, NULL. Junior
    SELECT x
    FROM (VALUES (1), (5), (10), (NULL)) AS t(x)
    WHERE x BETWEEN 5 AND 10;
  15. In what order does PostgreSQL return the values? The values of x are 2, NULL, 1. Middle
    SELECT x
    FROM (VALUES (2), (NULL), (1)) AS t(x)
    ORDER BY x DESC;
  16. How many rows does the query return? The values of x are 1, NULL, NULL, 1. Junior
    SELECT DISTINCT x
    FROM (VALUES (1), (NULL), (NULL), (1)) AS t(x);
  17. What does the query return? The values of x are 1, 2, NULL. Middle
    SELECT x
    FROM (VALUES (1), (2), (NULL)) AS t(x)
    WHERE x IN (1, NULL);
  18. A user has no middle name: middle_name = NULL. What does first_name || ' ' || middle_name || ' ' || last_name give in PostgreSQL? Junior

Take the quiz for this chapter · Read the explanation in the knowledge base

Aggregation

  1. How is WHERE different from HAVING? Junior
  2. How is COUNT(*) different from COUNT(phone)? Junior
  3. How do you find duplicated emails? Middle
  4. In users the country column holds UA, UA, NULL, NULL, PL. How many rows does the query return? Junior
    SELECT country, COUNT(*) FROM users GROUP BY country;
  5. A user without orders gets cnt = 1 while 0 is expected. Why, and how do you fix it? Middle
    SELECT u.id, COUNT(*) AS cnt
    FROM users u
    LEFT JOIN orders o ON o.user_id = u.id
    GROUP BY u.id;
  6. In PostgreSQL you need the number of completed and failed payments for each type in one query. How? Middle
  7. The qty column is integer with values 1 and 2. What does the query return in PostgreSQL? Middle
    SELECT SUM(qty) / COUNT(qty) AS manual_avg, AVG(qty) AS avg FROM items;
  8. What does the query return when no row passes WHERE? Junior
    SELECT COUNT(*) AS c, SUM(x) AS s
    FROM (VALUES (1), (2)) AS t(x)
    WHERE x > 5;
  9. Which user_id values does the query return? The orders rows (user_id, amount) are: (1, 10), (1, 20), (2, 50), (3, 5), (3, 5), (3, 5). Middle
    SELECT user_id
    FROM (VALUES (1, 10), (1, 20), (2, 50),
                 (3, 5), (3, 5), (3, 5)) AS o(user_id, amount)
    GROUP BY user_id
    HAVING SUM(amount) > 25
    ORDER BY user_id;
  10. What does the query return? The values of s are: ok, ok, failed, NULL. Middle
    SELECT COUNT(*) FILTER (WHERE s = 'ok') AS ok,
           COUNT(*) AS total
    FROM (VALUES ('ok'), ('ok'),
                 ('failed'), (NULL)) AS t(s);
  11. What does the query return? The values of x are 1, 1, NULL, 2. Junior
    SELECT COUNT(*), COUNT(x), COUNT(DISTINCT x)
    FROM (VALUES (1), (1), (NULL), (2)) AS t(x);
  12. What happens when this query runs in PostgreSQL? Junior
    SELECT user_id, status, COUNT(*)
    FROM (VALUES (1, 'new'), (1, 'paid'))
         AS o(user_id, status)
    GROUP BY user_id;
  13. What does the query return when there is no failed status? Middle
    SELECT SUM(CASE WHEN s = 'failed' THEN 1 END) AS failed
    FROM (VALUES ('ok'), ('ok')) AS t(s);

Take the quiz for this chapter · Read the explanation in the knowledge base

JOIN

  1. What will INNER JOIN of users and orders return? Junior
  2. How do you find users with no orders at all? Middle
    SELECT u.id, u.email
    FROM users u
    LEFT JOIN orders o ON o.user_id = u.id
    WHERE ???;
  3. Users: A has 2 orders, B has 1, C has none. How many rows does users LEFT JOIN orders return? Middle
  4. What will RIGHT JOIN of orders o with users u return? Junior
    SELECT u.email, o.id
    FROM orders o
    RIGHT JOIN users u ON u.id = o.user_id;
  5. How do you get an employee together with the name of their manager from a single table employees(id, name, manager_id)? Middle
  6. Why doesn't this query return users without orders? Middle
    SELECT u.email, o.id
    FROM users u
    LEFT JOIN orders o ON o.user_id = u.id
    WHERE o.status = 'PAID';
  7. After JOIN of orders and payments the order total came out twice as large. The most likely cause? Senior
  8. How many rows does the query return? Table a has two rows, b has three. Junior
    SELECT COUNT(*)
    FROM (VALUES (1), (2)) AS a(id)
    CROSS JOIN (VALUES ('x'), ('y'), ('z')) AS b(c);
  9. Which rows (a.id, b.id) does the query return? Table a has 1, 2 and b has 2, 3. Middle
    SELECT a.id, b.id
    FROM (VALUES (1), (2)) AS a(id)
    FULL JOIN (VALUES (2), (3)) AS b(id)
      ON a.id = b.id;
  10. How many rows does the query return? Each table has the values of k: 1 and NULL. Middle
    SELECT COUNT(*)
    FROM (VALUES (1), (NULL)) AS a(k)
    JOIN (VALUES (1), (NULL)) AS b(k)
      ON a.k = b.k;
  11. Does INNER JOIN give the same result whether the join condition is written in ON or moved to WHERE? Middle
  12. Both users and orders have an id column. What happens when this query runs? Junior
    SELECT id, email, amount
    FROM users u
    JOIN orders o ON o.user_id = u.id;

Take the quiz for this chapter · Read the explanation in the knowledge base

Subqueries, CTEs, set operations

  1. What will the query return if blocked_users.user_id has at least one NULL? Middle
    SELECT * FROM users
    WHERE id NOT IN (SELECT user_id FROM blocked_users);
  2. What is a CTE? Junior
    WITH paid AS (
      SELECT user_id, SUM(amount) AS total
      FROM orders WHERE status = 'PAID'
      GROUP BY user_id
    )
    SELECT u.email, p.total FROM users u JOIN paid p ON p.user_id = u.id;
  3. How do you find orders with an amount greater than the average? Middle
  4. a(x) holds 1, 2, 2, 3 and b(x) holds 2, 3, 4. What does the query return? Junior
    SELECT x FROM a
    EXCEPT
    SELECT x FROM b;
  5. Which query is guaranteed to return each user with at least one order exactly once, without DISTINCT or GROUP BY? Middle
  6. What does this recursive CTE return? Middle
    WITH RECURSIVE t(n) AS (
      SELECT 1
      UNION ALL
      SELECT n + 1 FROM t WHERE n < 3
    )
    SELECT n FROM t;
  7. PostgreSQL 14: a non-recursive CTE without side effects that is referenced once in the query. What does the planner do with it by default? Senior
    WITH recent AS (
      SELECT * FROM orders WHERE status = 'paid'
    )
    SELECT * FROM recent WHERE id = 5;
  8. What happens when this query runs? The orders table has four rows. Middle
    SELECT id
    FROM users
    WHERE id = (SELECT user_id FROM orders);
  9. What does the query return? The orders rows (id, user_id, amount) are: (1, 1, 10), (2, 1, 30), (3, 2, 5), (4, 2, 5). Middle
    SELECT id
    FROM orders o
    WHERE amount > (
      SELECT AVG(amount)
      FROM orders
      WHERE user_id = o.user_id
    );
  10. How many rows and which does the query return? The values of x: a has 1 and NULL, b has NULL and 2. Middle
    SELECT x FROM (VALUES (1), (NULL)) AS a(x)
    INTERSECT
    SELECT x FROM (VALUES (NULL), (2)) AS b(x);
  11. What happens if UNION combines SELECT id, email FROM users and SELECT id FROM orders? Junior
  12. What happens when this query runs in PostgreSQL? Middle
    SELECT amount * 2 AS doubled
    FROM orders
    WHERE doubled > 10;

Take the quiz for this chapter · Read the explanation in the knowledge base

Changing data and transactions

  1. How do DELETE, TRUNCATE and DROP differ? Junior
  2. A transfer: debit account A and credit B. Which ACID property guarantees that the transfer is never only half done? Middle
  3. What happens after UPDATE accounts SET balance = 0;? Junior
  4. Two parallel transfers read a balance of 100, each debits 80 and writes 20. What is this problem called? Middle
  5. How can tests clean up their data using transactions? Senior
  6. In psql with the default autocommit you ran an UPDATE without BEGIN and then ROLLBACK. What happens to the balance? Junior
    UPDATE accounts SET balance = balance - 100 WHERE id = 1;
    ROLLBACK;
  7. users has a UNIQUE constraint on email and the row with this email already exists. What happens when the statement runs again? Middle
    INSERT INTO users (email, name)
    VALUES ('a@x.io', 'Anna')
    ON CONFLICT (email) DO NOTHING;
  8. Transaction A changed the balance but has not issued COMMIT yet. What does session B see in PostgreSQL at READ COMMITTED? Middle
    -- accounts: (id = 1, balance = 100)
    -- A: BEGIN;
    -- A: UPDATE accounts SET balance = 50
    --    WHERE id = 1;
    -- B: SELECT balance FROM accounts
    --    WHERE id = 1;
  9. Session A opened a REPEATABLE READ transaction and read the balance, then B changed it and committed. What happens to the UPDATE in A? Middle
    -- accounts: (id = 1, balance = 100)
    -- A: BEGIN ISOLATION LEVEL REPEATABLE READ;
    -- A: SELECT balance FROM accounts
    --    WHERE id = 1;            -- 100
    -- B: UPDATE accounts SET balance = 70
    --    WHERE id = 1;
    -- B: COMMIT;
    -- A: UPDATE accounts
    --    SET balance = balance - 10
    --    WHERE id = 1;
  10. In PostgreSQL an INSERT inside a transaction violated UNIQUE (the email already exists). What happens to the following commands? Middle
    -- users already has a@x.io (UNIQUE email)
    BEGIN;
    INSERT INTO users (email)
    VALUES ('a@x.io');
    -- ERROR: duplicate key value ...
    SELECT 1;
    COMMIT;
  11. An autotest creates a user in the database and needs its id right away. What does RETURNING id do in PostgreSQL? Junior
    INSERT INTO users (email)
    VALUES ('qa@test.io')
    RETURNING id;
  12. The SQL standard allows phantom reads at REPEATABLE READ. How is it in PostgreSQL? Senior
  13. Transaction A updated row 1 and waits for row 2, while transaction B updated row 2 and waits for row 1. What does PostgreSQL do with default settings? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

Database structure

  1. What is a foreign key? Junior
  2. Which column type is right for money amounts? Middle
  3. What is the price of an index? Junior
  4. Why use timestamptz rather than timestamp for operation times in fintech? Middle
  5. What happens to this INSERT in PostgreSQL? Middle
    CREATE TABLE products (
      id    int PRIMARY KEY,
      price numeric CHECK (price > 0)
    );
    INSERT INTO products VALUES (1, NULL);
  6. What happens to this DELETE in PostgreSQL if no ON DELETE was given when the foreign key was created? Junior
    CREATE TABLE orders (
      id      int PRIMARY KEY,
      user_id int REFERENCES users (id)
    );
    -- users: id 1; orders: (10, 1), (11, 1)
    DELETE FROM users WHERE id = 1;
  7. For which query in PostgreSQL 17 does this index give a narrow search range instead of a full index scan? Middle
    -- orders.user_id bigint, orders.created_at timestamptz
    CREATE INDEX idx_orders_user_created
      ON orders (user_id, created_at);
  8. The plan shows Seq Scan although an index on email exists. The table is large and statistics are fresh. What should be done? Middle
    -- users: 3 million rows
    CREATE INDEX idx_users_email
      ON users (email);
    
    EXPLAIN SELECT * FROM users
    WHERE lower(email) = 'qa@test.io';
  9. What happens to this migration in PostgreSQL if users already has rows? Junior
    -- users: 1000 rows
    ALTER TABLE users
      ADD COLUMN phone text NOT NULL;
  10. A tester only wants to look at the plan of a delete. What does this command do in PostgreSQL with autocommit? Junior
    -- orders: 5 million rows, autocommit
    EXPLAIN ANALYZE
    DELETE FROM orders
    WHERE status = 'old';
  11. orders has 5 million rows, 95% have status = 'done', statistics are fresh and there is a plain B-tree index on status. Why will the planner probably choose Seq Scan for WHERE status = 'done'? Middle
  12. In the table orders(order_id PK, customer_id, customer_city) the city is determined by the customer, not by the order. Which normal form is violated? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

Window functions

  1. Salaries 100, 100, 90 in descending order. What do ROW_NUMBER, RANK and DENSE_RANK give? Middle
  2. In PostgreSQL, how do you select the last transaction of each account? Middle
  3. What is in the prev column for the very first row by date? Junior
    SELECT day, amount,
      LAG(amount) OVER (ORDER BY day) AS prev
    FROM sales;
  4. Rows (day, amount): (1, 10), (2, 5), (2, 7). Which running totals does the query give in PostgreSQL? Senior
    SELECT day, amount,
      SUM(amount) OVER (ORDER BY day) AS running
    FROM sales
    ORDER BY day;
  5. Rows (id, x): (1, a), (2, b), (3, c). What does the last column return in PostgreSQL? Senior
    SELECT id, x,
      LAST_VALUE(x) OVER (ORDER BY id) AS last
    FROM t
    ORDER BY id;
  6. A user's activity days are 1, 2, 3, 5, 6 (unique, days of the month). What is the same for all days of one consecutive streak? Senior
  7. The task is “the two highest salary levels” in a department. How many rows does the query return if the salaries are 100, 100, 90, 80? Middle
    -- employees: (dept, salary)
    -- (A,100), (A,100), (A,90), (A,80)
    SELECT salary FROM (
      SELECT salary,
        DENSE_RANK() OVER (
          PARTITION BY dept
          ORDER BY salary DESC) AS r
      FROM employees
    ) x
    WHERE r <= 2;
  8. What does this query return in PostgreSQL when the row number is filtered in WHERE? Middle
    SELECT id,
      ROW_NUMBER() OVER (ORDER BY id) AS rn
    FROM users
    WHERE rn = 1;
  9. What diff values does the query give for days 1, 2, 3 with amounts 10, 15, 12? Middle
    -- sales: (day, amount)
    -- (1, 10), (2, 15), (3, 12)
    SELECT day,
      amount - LAG(amount, 1, 0)
        OVER (ORDER BY day) AS diff
    FROM sales
    ORDER BY day;
  10. What does the ma column return for days 1, 2, 3 with amounts 10, 20, 60? Middle
    -- m: (day, amount)
    -- (1, 10), (2, 20), (3, 60)
    SELECT day,
      AVG(amount) OVER (
        ORDER BY day
        ROWS BETWEEN 1 PRECEDING
                 AND CURRENT ROW
      ) AS ma
    FROM m
    ORDER BY day;
  11. What running-total values does the query give for the rows (acc, day, amount): (A,1,10), (A,2,5), (B,1,7)? Middle
    -- r: (acc, day, amount)
    -- (A,1,10), (A,2,5), (B,1,7)
    SELECT acc, day,
      SUM(amount) OVER (
        PARTITION BY acc
        ORDER BY day) AS running
    FROM r
    ORDER BY acc, day;
  12. In PostgreSQL, NTILE(4) is applied to 10 rows. How many rows go into each of the four groups (numbers 1, 2, 3, 4)? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

SQL in QA work

  1. How do you check through the DB that an API transfer was processed correctly? Middle
  2. How do you test a search field for SQL injection? Middle
  3. A client sent POST /payments twice with the same Idempotency-Key. Which database check proves idempotency? Middle
  4. An automated test compares the query result with the expected id list 1, 2, 3. Why can the test become flaky? Middle
    SELECT id FROM users LIMIT 3;
  5. The application uses soft delete through the deleted_at column. DELETE /users/5 returned 204. What should the database show? Junior
  6. EXPLAIN ANALYZE of the query below in PostgreSQL shows a Seq Scan on orders (5 million rows) taking 800 ms, while user_id = 42 has only about 50 rows. What does it mean? Middle
    EXPLAIN ANALYZE
    SELECT * FROM orders WHERE user_id = 42;
  7. A QA engineer looks for “orphan” orders. Which ids does the query return and what does that mean for the integrity check? Middle
    -- users: id 1, 2
    -- orders (id, user_id):
    --   (10, 1), (11, 3), (12, NULL)
    SELECT o.id
    FROM orders o
    LEFT JOIN users u ON u.id = o.user_id
    WHERE u.id IS NULL
    ORDER BY o.id;
  8. A QA engineer looks for users without orders. What does this query return in PostgreSQL? Middle
    -- users: id 1, 2, 3
    -- orders.user_id: 1, NULL
    SELECT id
    FROM users
    WHERE id NOT IN (
      SELECT user_id FROM orders
    );
  9. An autotest created a user and its orders. The cleanup DELETE FROM users WHERE email = 'qa@test.io' fails with a foreign key error. What is right? Junior
  10. A payment was created at 23:30 UTC on 1 March. Which date does the query show in a session with the time zone Europe/Kyiv (UTC+2)? Middle
    -- payments.created_at timestamptz
    --   = '2026-03-01 23:30:00+00'
    SET TimeZone = 'Europe/Kyiv';
    
    SELECT created_at::date
    FROM payments;
  11. Which accounts does this reconciliation of balances against the transaction history return? Middle
    -- accounts: (A,100), (B,50), (C,0)
    -- transactions (account_id, amount):
    --   (A,60), (A,40), (B,30)
    SELECT a.id
    FROM accounts a
    LEFT JOIN transactions t
      ON t.account_id = a.id
    GROUP BY a.id, a.balance
    HAVING a.balance
      <> COALESCE(SUM(t.amount), 0);
  12. POST /payments returns 202 and the DB record appears asynchronously within 1-3 s. How should an autotest check the database? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

Interview tasks

  1. You need departments where the average salary is above the company average. Which query is correct? Junior
    employees(id, department_id, salary)
  2. You need employees with the second highest distinct salary in their department (salaries in a department may repeat). Which function fits? Middle
    employees(id, department_id, salary)
  3. You need users who bought both product A and product B. One user may have bought A several times. Which query is correct? Middle
    purchases(id, user_id, product)
  4. After a migration you must find ids that exist in old_users but are missing from new_users. Which query does it? Middle
  5. What does the “second highest salary” query return if all three employees earn 300? Middle
    -- employees.salary: 300, 300, 300
    SELECT MAX(salary)
    FROM employees
    WHERE salary < (
      SELECT MAX(salary) FROM employees
    );
  6. The third highest unique salary is needed. What does the query return for the salaries 300, 300, 250, 250, 200? Middle
    -- employees.salary:
    -- 300, 300, 250, 250, 200
    SELECT DISTINCT salary
    FROM employees
    ORDER BY salary DESC
    LIMIT 1 OFFSET 2;
  7. How many rows does the “find duplicate emails” query return for this data? Middle
    -- users (id, email):
    -- (1,'a@x.io'), (2,'b@x.io'),
    -- (3,'a@x.io'), (4,NULL), (5,NULL)
    SELECT email, COUNT(*)
    FROM users
    GROUP BY email
    HAVING COUNT(*) > 1;
  8. Which ids remain in the table after this DELETE? Middle
    -- users (id, email):
    -- (1,'a'), (2,'a'), (3,'b'), (4,'a')
    DELETE FROM users x
    USING users y
    WHERE x.email = y.email
      AND x.id > y.id;
  9. Which values does the query “find the missing ids from 1 to 6” return if the table has ids 1, 2, 4, 6? Middle
    -- t.id: 1, 2, 4, 6
    SELECT s.n
    FROM generate_series(1, 6) AS s(n)
    LEFT JOIN t ON t.id = s.n
    WHERE t.id IS NULL
    ORDER BY s.n;
  10. The number of paid orders per user is needed, zeros included. What does this query return? Middle
    -- users: 1, 2, 3
    -- orders (id, user_id, status):
    --   (1,1,'paid'), (2,2,'pending'),
    --   (3,1,'paid')
    SELECT u.id, COUNT(o.id) AS paid
    FROM users u
    LEFT JOIN orders o ON o.user_id = u.id
    WHERE o.status = 'paid'
    GROUP BY u.id;
  11. The query should show the percentage of failed transactions per type but returns 0 for both types. Why? Middle
    -- transactions (type, status):
    --   card: 3 ok, 1 failed
    --   sepa: 1 ok, 1 failed
    SELECT type,
      COUNT(*) FILTER (
        WHERE status = 'failed')
      / COUNT(*) * 100 AS pct
    FROM transactions
    GROUP BY type;
  12. Which employees earn more than their manager? Junior
    -- employees (id, name, manager_id, salary):
    -- (1,Anna,NULL,300) (2,Bohdan,1,350)
    -- (3,Olha,1,250)    (4,Ivan,2,360)
    -- (5,Kira,2,340)
    SELECT e.name
    FROM employees e
    JOIN employees m ON e.manager_id = m.id
    WHERE e.salary > m.salary;
  13. What does this query return in PostgreSQL and how does the result differ from AVG(salary)? Middle
    WITH salaries(salary) AS (
      VALUES (100), (200), (300), (1000)
    )
    SELECT percentile_cont(0.5)
           WITHIN GROUP (ORDER BY salary)
    FROM salaries;

Take the quiz for this chapter · Read the explanation in the knowledge base