Match Work Dates with Correct Billing Rate Using SQL!
In this video, we’ll solve a real-world SQL problem that’s often asked in interviews and used in business analytics! We have two tables — one showing employee billing rates over time, and another with hours worked. Our goal? To calculate the total billed amount for each employee by matching every work date with the correct billing rate period using powerful SQL functions like LEAD() and DATE_ADD() 💡 You’ll learn:tion! You’ll learn how to use self joins, aggregations, and grouping techniques to solve this business-focused SQL problem step by step. Medium LINK -https://medium.com/@singole/sql-real-world-problem-match-work-dates-with-correct-billing-rate-using-window-functions-ca29cbf763b8?postPublishedType=initial 🧩 SQL Table Setup: --------------------------------------------------------------------------------------------- -- Create Billings Table CREATE TABLE billings ( emp_name VARCHAR(10), bill_date DATE, bill_rate INT ); -- Delete existing data (if any) DELETE FROM billings; -- Insert sample data INSERT INTO billings VALUES ('Sachin', '1990-01-01', 25), ('Sehwag', '1989-01-01', 15), ('Dhoni', '1989-01-01', 20), ('Sachin', '1991-02-05', 30); -- Create HoursWorked Table CREATE TABLE HoursWorked ( emp_name VARCHAR(20), work_date DATE, bill_hrs INT ); -- Insert sample data INSERT INTO HoursWorked VALUES ('Sachin', '1990-07-01', 3), ('Sachin', '1990-08-01', 5), ('Sehwag', '1990-07-01', 2), ('Sachin', '1991-07-01', 4); -- Display data SELECT * FROM billings; SELECT * FROM HoursWorked; --------------------------------------------------------------------------------------------- 💥 Tech Used: MySQL 8.0 Window Functions (LEAD) Common Table Expressions (CTEs) 📂 Additional Resources: 🔗 Dataset : https://github.com/shubhamringole/SQL-Interview-questions/tree/main/SQL%20Problem%20Product%20Pairs%20Most%20Commonly%20Purchased%20Together 🔗 My Repository: https://github.com/shubhamringole/SQL-Interview-questions/tree/main 🔗 Related Blog: https://medium.com/@singole 📺 Complete SQL Playlist: 🎥 Learn SQL Complete Guide This playlist takes you from beginner to advanced, covering: 1. Introduction to SQL Learn to Query Databases Like a Pro https://www.youtube.com/watch?v=K49-QaA2Eg4 2.How to Install MySQL Workbench - A step-by-step guide on downloading, installing, and setting up MySQL Workbench. https://youtu.be/SzM3zNLUN1Q 3.SQL Fundamentals: Data Types, Keys, and Constraints https://youtu.be/7mVoPTBEEFQ 4.SQL Table Operations : Create, Delete, Drop, Truncate, and Alter | Lesson 4 | Introduction to SQL https://youtu.be/nRvrLPbFBZU 5.SELECT Statement | WHERE Clause with Examples and Operators in SQL |Lesson 5 | Introduction to SQL https://youtu.be/HRgmAt0sOT8 6.How to Import an Excel CSV File into MySQL A Step by Step Guide| Lesson 4 | Introduction to SQL https://youtu.be/LJ4xjNi4ZA4 7.Mastering SQL GROUP BY and HAVING Clauses Explained https://www.youtube.com/watch?v=0mZGT_7UH3A&list=PLSFRPxOkWfFBKeFXsKGhU17OCLz_yzelm&index=7 8.Mastering SQL JOINs: Complete Guide with Examples | INNER & LEFT JOIN Lesson 8 | Introduction to SQL https://www.youtube.com/watch?v=xplv8r9YXuc 9. Right Join, Cross Join, and Outer Join Explained | Lesson 9 | Introduction to SQL https://youtu.be/EdZ2OqyLTuA 10.SQL Subqueries Explained: Unlock Advanced Querying Techniques https://youtu.be/O-HZrJAuro0 11.SQL CASE Statement Explained: Boost Your Query Skills! | Lesson 11 https://www.youtube.com/watch?v=o8RVwoqmq8U&t=1s 12.Master SQL Window Functions: RANK & DENSE RANK https://www.youtube.com/watch?v=4wfqcdfKlkM&t=22s 13. The Magic of Wildcards in SQL: Unlocking Pattern Matching Techniques https://youtu.be/6ansExs8SYQ 14.SQL SELF JOIN | UNION & UNION ALL in SQL | Lesson 14 https://youtu.be/bpZscFr6BsQ 🕒 Timecodes: 00:00 Intro 00:44 Problem Statement 02:40 Understanding the Logic 03:5 SQL Query Walkthrough 10:30 Final Thoughts 📚 More Learning: 🧠 Medium Blog: Understanding SQL CTEs 📸 Instagram: @analystmind 🌐 Medium Profile: @singole 💬 Stay Connected: If you enjoyed this SQL problem, make sure to Like 👍, Comment 💬, and Subscribe 🔔 for more SQL practice questions and real-world use cases. #sql #sqlproblem #mysql #dataanalysis #recommendationsystem #joins #ecommerce #sqlproject #analystmind #sqlpractice
Download
0 formatsNo download links available.