Job interviews2:35
Job interviews · Data analyst · Advanced
Data Analyst: SQL Questions and a Strange Numberمقابلة محلل بيانات: أسئلة SQL ورقم غريب
- Hany
- Yasmin
0:00 / 2:35
Transcript
- HanyThanks for joining, Yasmin. I'll ask a few SQL questions and one about data quality. Please explain your thinking as you go.
- YasminOf course. I'll say my assumptions first.
- HanyWe 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?
- YasminThe 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.
- HanyAnd if you want customers who have no orders at all?
- YasminI'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.
- HanyNext. For each customer, I want their most recent order. How would you write that?
- YasminI'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.
- HanyWhy not just use group by?
- YasminGroup 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.
- HanyCan you filter on that row number in the where clause of the same query?
- YasminNo, 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.
- HanyLast scenario. The revenue dashboard shows a drop of forty percent on Monday compared with last Monday. The manager is worried. What do you do?
- YasminFirst 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.
- HanyAnd what do you tell the manager in the meantime?
- YasminSomething 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.
- HanyGood. Do you have any questions for me?
- YasminYes. Who owns data quality in your team, and how do you find out when a source changes?