Spokalyالإنجليزية تبدأ من السمع
مقابلات العمل · محلل بيانات · متقدّم

مقابلة محلل بيانات: أسئلة SQL ورقم غريبData Analyst: SQL Questions and a Strange Number

  • Hany
  • Yasmin
0:00 / 2:35
الشريط الملوّن مقسوم حسب المتكلّم، فترى من يتحدّث ومتى.

النص

  1. Hany
    Thanks for joining, Yasmin. I'll ask a few SQL questions and one about data quality. Please explain your thinking as you go.
  2. Yasmin
    Of course. I'll say my assumptions first.
  3. Hany
    We have a table of customers and a table of orders. A customer can have many orders. A colleague joins them and counts customers, but the number is too high. What happened?
  4. Yasmin
    The join returns one row per order, so a customer with five orders appears five times. Counting rows counts orders, not customers. I'd count distinct customer IDs, or aggregate the orders first and then join.
  5. Hany
    And if you want customers who have no orders at all?
  6. Yasmin
    I'd use a left join from customers to orders and keep the rows where the order ID is null. An inner join would remove exactly those customers.
  7. Hany
    Next. For each customer, I want their most recent order. How would you write that?
  8. Yasmin
    I'd use a window function. I'd number the orders for each customer, partitioned by customer ID and ordered by order date, newest first. Then I'd keep only the rows where the number is one.
  9. Hany
    Why not just use group by?
  10. Yasmin
    Group by collapses the rows into one row per customer, so I would lose the other columns of the order, like its ID and amount, unless I do another join. A window function keeps every row and adds a number to it.
  11. Hany
    Can you filter on that row number in the where clause of the same query?
  12. Yasmin
    No, I don't think so. In standard SQL the where clause is applied before window functions are calculated, so I'd put the ranking in a subquery or a common table expression and filter outside it.
  13. Hany
    Last scenario. The revenue dashboard shows a drop of forty percent on Monday compared with last Monday. The manager is worried. What do you do?
  14. Yasmin
    First I wouldn't send a conclusion. I'd check whether the data is complete: did the daily data load finish, and are there missing rows for some stores? Then I'd compare with another source, like the finance system, and look at whether a filter or a definition changed.
  15. Hany
    And what do you tell the manager in the meantime?
  16. Yasmin
    Something short and honest: 'The number looks unusual. I'm checking whether it's a data problem or a real drop. I'll update you by two o'clock.' That avoids panic and gives a time.
  17. Hany
    Good. Do you have any questions for me?
  18. Yasmin
    Yes. Who owns data quality in your team, and how do you find out when a source changes?