Skip to content
Interview Questions

Data Analyst Interview Questions & Answers: Set 20, Final Mock Interview

100 harder, mixed-industry questions with model answers for a full mock interview: SQL, Excel, statistics, Python, Power BI, business cases, AI and behavioral.

  • Data Analyst
  • Final Mock Interview (Mixed, Harder)
  • Set 20 of 20
  • Data
  • SQL
  • Excel
  • Python
  • Power BI
  • AI

Free with login: questions 1 and 2 are open to everyone, all 100 after you log in.

Part of Bundle 4 · People, Public Sector & Final Mock

What's inside

  • 100 questions, each with a model answer
  • SQL · Excel · Statistics · Python · Power BI · Business Case · AI · Behavioral
  • SQL and Python answers include working code
  • Set 20 of 20 · read free on DS360 with login

Questions and answers

2 of 100 questions shown · Set 20 of 20 · Final Mock Interview (Mixed, Harder)

SQL

  1. 1.Write a query to find users whose spending increased every month for 3 months in a row.

    Answer: Aggregate spend to one row per user per month, then use LAG to compare each month with the previous two. A user qualifies when month 3 > month 2 > month 1 and the three months are consecutive. Tables assumed: orders(user_id, order_date, amount). Trap: a month with no orders has no row, so LAG could silently skip a gap. The check on mon2 makes sure the months really are back to back.

    SQL
    WITH m AS (
      SELECT user_id, DATE_TRUNC('month', order_date) AS mon,
             SUM(amount) AS spend
      FROM orders
      GROUP BY 1, 2
    ), l AS (
      SELECT user_id, mon, spend,
             LAG(spend, 1) OVER w AS p1,
             LAG(spend, 2) OVER w AS p2,
             LAG(mon, 2)   OVER w AS mon2
      FROM m
      WINDOW w AS (PARTITION BY user_id ORDER BY mon)
    )
    SELECT DISTINCT user_id
    FROM l
    WHERE spend > p1 AND p1 > p2
      AND mon2 = mon - INTERVAL '2 months';
  2. 2.Calculate the median order value in SQL without a built-in MEDIAN function.

    Answer: Number the rows in order of value and count the total. Then average the middle row, or the two middle rows when the count is even. With integer division, (cnt+1)/2 and (cnt+2)/2 give the same row when cnt is odd and the two middle rows when it is even. Table assumed: orders(order_id, amount). In PostgreSQL you can also use PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY amount), but interviewers usually want the manual method.

    SQL
    WITH r AS (
      SELECT amount,
             ROW_NUMBER() OVER (ORDER BY amount) AS rn,
             COUNT(*) OVER ()                    AS cnt
      FROM orders
    )
    SELECT AVG(amount) AS median_order_value
    FROM r
    WHERE rn IN ((cnt + 1) / 2, (cnt + 2) / 2);

Loading all 100 questions…

Related resources

See all resources →

Data Analyst Interview Questions & Answers: Set 20, Final Mock Interview | Data Solution 360