Skip to content
Interview Questions

Data Analyst Interview Questions & Answers: Set 1, E-commerce Fundamentals

100 interview questions with model answers for freshers, set in E-commerce Fundamentals: SQL, Excel, statistics, Python, Power BI, business cases, AI and behavioral.

  • Data Analyst
  • E-commerce Fundamentals
  • Set 1 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 1 · Commerce & Customers

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 1 of 20 · read free on DS360 with login

Questions and answers

2 of 100 questions shown · Set 1 of 20 · E-commerce Fundamentals

SQL

  1. 1.Write a query to find the second-highest order value from an orders table. How would you handle ties?

    Answer: Rank the distinct order values and pick rank 2. Using DENSE_RANK() handles ties best: if two orders share the top value, the next distinct value still gets rank 2, and every order with that second-highest value is returned. Common trap: ORDER BY order_value DESC LIMIT 1 OFFSET 1 returns the top value again when the highest is tied. Also filter out NULLs, because PostgreSQL sorts NULLs first in DESC order. Table assumed: orders(order_id, order_value). For just the number, SELECT MAX(order_value) FROM orders WHERE order_value < (SELECT MAX(order_value) FROM orders) also works.

    SQL
    SELECT order_id, order_value
    FROM (
      SELECT order_id, order_value,
             DENSE_RANK() OVER (ORDER BY order_value DESC) AS rnk
      FROM orders
      WHERE order_value IS NOT NULL
    ) t
    WHERE rnk = 2;
  2. 2.What is the difference between WHERE and HAVING? Give an example where only HAVING works.

    Answer: WHERE filters individual rows before grouping; HAVING filters groups after aggregation. So WHERE cannot use aggregates like COUNT() or SUM(), because they don't exist yet at that stage. Example where only HAVING works: find customers with more than 5 delivered orders. The status filter belongs in WHERE (row level, also faster because fewer rows get grouped), while the count condition must go in HAVING. Rule of thumb: filter rows early with WHERE, and use HAVING only for conditions on aggregated values.

    SQL
    SELECT customer_id, COUNT(*) AS delivered_orders
    FROM orders
    WHERE status = 'delivered'
    GROUP BY customer_id
    HAVING COUNT(*) > 5;

Loading all 100 questions…

Related resources

See all resources →