Forward Fill NULLs using FIRST_VALUE() | This SQL Interview Trick Blew My Mind 🤯 | SQL Interview
Автор: Aditya Bansal
Загружено: 2025-07-31
Просмотров: 2339
🔥 SQL Interview Favorite – Forward Fill NULLs Like a Pro!
Have you ever been asked to forward fill `NULL` values in SQL with the last non-NULL value?
This is a classic data engineering interview question — and many folks get stuck here!
👨💻 Problem:
You're given a `Stocks` table with `DateKey`, `StockName`, and `Price`.
You need to derive a new column `MarketPrice` that fills `NULL` values with the last known non-NULL price — in the correct order.
Insert Statements:
create table Stocks
(DateKey Date,
StocksName varchar(20),
Price int
);
insert into Stocks values
('20230101','Infosys',1400)
,('20230102','Infosys',null)
,('20230103','Infosys',1450)
,('20230104','Infosys',null)
,('20230105','Infosys',null)
,('20230105','Infosys',null)
,('20230101','Reliance',2300)
,('20230102','Reliance',NULL)
,('20230103','Reliance',null)
,('20230104','Reliance',2375)
,('20230105','Reliance',2400)
,('20230106','Reliance',null)
In this video, I’ll walk you through:
✅ How to think through the logic
✅ Using `FIRST_VALUE()` cleverly to solve this
✅ A real-world approach that’ll impress any interviewer
If you're preparing for SQL interviews, this is a must-know trick 💡
No need to memorize — just understand the thought process.
🧠 Whether you're applying for FAANG or startups, mastering NULL handling and window functions can be a game-changer.
Boost your SQL & data skills daily:
🔗 Follow Aditya Bansal on LinkedIn:
/ adityabansal095
📢 Join the SQL JUNCTION Telegram Channel (1,400+ members):
[https://t.me/sqljunction]
🚀 Daily content | Job prep | Real interview questions
Keywords: SQL Server Interview Questions ,complex analysis interview questions,sql interview for freshers, sql amazon interview questions, sql hackerrank challenges
👉 Don’t forget to like, comment, and subscribe for more real SQL questions!
#SQLInterview #SQLServer #SQLChallenge #DataEngineering #SQLTutorial #AdityaBansal #SQLJunction #DataScienceInterview #SQLQuestion #TechInterview #AdvancedSQL #interviewprep
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: