SQL Interview Question on DATEPART + SUBSTRING | Real-World Query | Day 3 #30DaySQLChallenge
Welcome to Day 3 of the #30DaySQLChallenge!
In this video, we tackle a real-world SQL interview question using a smart combination of DATEPART and SUBSTRING to filter dates based on weekday patterns. This technique is commonly used in data transformation and ETL pipelines — and is a favorite in SQL interviews!
🔍 What You'll Learn:
✅ How to use DATEPART(WEEKDAY, column)
✅ How to combine SUBSTRING with CASE WHEN
✅ Real-life logic to dynamically filter dates
✅ Best practices to write clean, readable SQL
Data:
create table Day_Indicator
(
Product_ID varchar(10),
Day_Indicator varchar(7),
Dates date
);
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'04-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'05-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'06-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'07-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'08-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'09-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'10-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'04-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'05-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'06-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'07-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'08-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'09-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'10-Mar-2024', 102));
Whether you're preparing for a data analyst, engineer, or BI interview — this SQL challenge is a must-practice!
📌 Challenge Yourself:
Try modifying the query to exclude weekends or only include alternate days. Share your solution in the comments!
🔔 Subscribe for the full #30DaySQLChallenge playlist!
👍 Like the video if this helped, and comment below with your questions or solutions.
Follow me on :
https://www.linkedin.com/in/shubhamsinghrao/
https://www.instagram.com/thetechtownttt
https://techtown.in/
Видео SQL Interview Question on DATEPART + SUBSTRING | Real-World Query | Day 3 #30DaySQLChallenge канала The Tech Town
In this video, we tackle a real-world SQL interview question using a smart combination of DATEPART and SUBSTRING to filter dates based on weekday patterns. This technique is commonly used in data transformation and ETL pipelines — and is a favorite in SQL interviews!
🔍 What You'll Learn:
✅ How to use DATEPART(WEEKDAY, column)
✅ How to combine SUBSTRING with CASE WHEN
✅ Real-life logic to dynamically filter dates
✅ Best practices to write clean, readable SQL
Data:
create table Day_Indicator
(
Product_ID varchar(10),
Day_Indicator varchar(7),
Dates date
);
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'04-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'05-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'06-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'07-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'08-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'09-Mar-2024', 102));
insert into Day_Indicator values ('AP755', '1010101', CONVERT(DATE,'10-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'04-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'05-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'06-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'07-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'08-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'09-Mar-2024', 102));
insert into Day_Indicator values ('XQ802', '1000110', CONVERT(DATE,'10-Mar-2024', 102));
Whether you're preparing for a data analyst, engineer, or BI interview — this SQL challenge is a must-practice!
📌 Challenge Yourself:
Try modifying the query to exclude weekends or only include alternate days. Share your solution in the comments!
🔔 Subscribe for the full #30DaySQLChallenge playlist!
👍 Like the video if this helped, and comment below with your questions or solutions.
Follow me on :
https://www.linkedin.com/in/shubhamsinghrao/
https://www.instagram.com/thetechtownttt
https://techtown.in/
Видео SQL Interview Question on DATEPART + SUBSTRING | Real-World Query | Day 3 #30DaySQLChallenge канала The Tech Town
sql power bi data science ml data analysis data analyst tech town the tech town SQL SQL interview questions SQL challenge SQL weekday filter DATEPART SQL substring sql real world sql 30DaySQLChallenge sql case when sql date functions sql for data analyst sql practice learn sql sql for beginners interview sql question etl sql logic sql weekday logic sql weekday interview sql challenge day 3 sql interview questions sql problem solving sql queries
Комментарии отсутствуют
Информация о видео
30 июня 2025 г. 18:58:32
00:14:35
Другие видео канала