TheCodingCo

147 posts

TheCodingCo banner
TheCodingCo

TheCodingCo

@thecoding_co

TheCodingCo SQL • Python • Data Analytics • Development Learn coding, data & tech skills through practical examples and interview questions. YouTube ↓

शामिल हुए Temmuz 2023
51 फ़ॉलोइंग5 फ़ॉलोवर्स
TheCodingCo
TheCodingCo@thecoding_co·
So we need two roles: Employee Manager From the same table. Solution: Self join Employees table e.manager_id = m.employee_id Then compare: e.salary > m.salary This gives employees earning more than their manager.
English
1
0
0
0
TheCodingCo
TheCodingCo@thecoding_co·
SQL Interview Question #10 🧵 Find employees who earn more than their manager. Sounds simple… but many candidates freeze. The tricky part is not the comparison. It’s understanding the relationship. Employees and managers are stored in the SAME table. manager_id → employee_id
English
1
0
0
1
TheCodingCo
TheCodingCo@thecoding_co·
Then filter: rnk = 1 This gives the top product for each month.
English
1
0
0
5
TheCodingCo
TheCodingCo@thecoding_co·
SQL Interview Question #9 🧵 Find the top-selling product each month. Sounds like GROUP BY… but it’s more than that. Many candidates calculate total sales correctly… but get stuck finding the top product per month.
English
1
0
0
6
TheCodingCo
TheCodingCo@thecoding_co·
Example: LAG(temperature) OVER (ORDER BY record_date) Then filter: temperature > previous_temperature That’s it.
English
1
0
0
8
TheCodingCo
TheCodingCo@thecoding_co·
SQL Interview Question #8 🧵 Find days where temperature was higher than the previous day. Sounds simple… but many candidates struggle. The tricky part is not the comparison. It’s accessing the previous row correctly.
English
1
0
0
10
TheCodingCo
TheCodingCo@thecoding_co·
The real idea: Access the previous row directly. Use LAG() LAG lets you look at a value from the previous row without writing a join. Example: amount + LAG(amount) OVER (ORDER BY transaction_date) First row returns NULL (no previous row). If needed, use ISNULL or COALESCE.
English
1
0
0
8
TheCodingCo
TheCodingCo@thecoding_co·
SQL Interview Question #7 🧵 Show current amount + previous amount in the same row. Sounds simple… but many people overcomplicate it. Most candidates think about self joins. But self joins can get messy quickly.
English
1
0
0
10
TheCodingCo
TheCodingCo@thecoding_co·
Correct idea: Start with all customers. Then check who failed to match with Orders. Example pattern: LEFT JOIN Orders WHERE o.customer_id IS NULL
English
1
0
0
9
TheCodingCo
TheCodingCo@thecoding_co·
SQL Interview Question #6 🧵 Find customers who never placed an order. Sounds simple… but many candidates still get it wrong. Most people immediately write: INNER JOIN Customers and Orders.
English
1
0
0
11
TheCodingCo
TheCodingCo@thecoding_co·
RANK Allows ties. But after a tie, rank numbers skip. Example: 1, 2, 2, 4 DENSE_RANK Also allows ties. But does NOT skip numbers. Example: 1, 2, 2, 3
English
1
0
0
4
TheCodingCo
TheCodingCo@thecoding_co·
SQL Window Functions every Data Analyst should know 🧵 ROW_NUMBER RANK DENSE_RANK LAG LEAD These functions show up in many SQL interviews. Example question: “Find the second highest salary in each department.”
English
1
0
0
5