Must DO - SQL Interview Query | Forward Fill Values for NULL Records | Last Not NULL puzzle | FAANG

In this tutorial, we write a SQL Query to forward fill values for NULL records. This is also known as the Last Not NULL puzzle.
We make use of Windows function FIRST_VALUE. We also write the query using MAX function.
This is a FAANG interview query.
The practice data and SQL Queries are available here-
know-star.blogspot.com/2022/0...
Difference between Count(*), Count(1) and Count(column)
• SQL Interview Question...
How to install SQL Server for practice?
• How to install SQL Ser...
Check out the complete list of SQL Query Interview Questions -
• SQL Query Interview Qu...
Best Data Science / Analytics / SQL courses
Learn SQL Basics for Data Science Specialization
imp.i384100.net/qnXYk5
Data Science Fundamentals with Python and SQL Specialization
imp.i384100.net/mgVYre
Beginners to Python Programming
skillshare.eqcm.net/GjMakm
Data Science and Business Analytics with Python
skillshare.eqcm.net/JrM1Aq
Get 40% OFF of Skillshare with code FLASH40 - October 2022
skillshare.eqcm.net/c/3299742...
Python for Everybody Specialization
imp.i384100.net/DVz7Aj
Google Data Analytics Professional Certificate
imp.i384100.net/OR37oQ
Coursera Plus - Data Science Career Skills
imp.i384100.net/c/3299742/132...
Please do not forget to like, subscribe and share.
For enrolling and enquiries, please contact us at
Website - knowstar.org/
Instagram - / learn.knowstar
Facebook - / knowstartrainings
Linkedin - www.linkedin.com/company/know...
Email - learn@knowstar.org

Пікірлер: 47

  • @jamesgg9950
    @jamesgg9950 Жыл бұрын

    "Count(Rate) OVER..." relies on the aggregate function treating NULL as invalid. Even though it will work in nearly 100% of cases, it's like abbreviating "cumulative group count" as "cum grp cnt", it says something about you that only experts will notice... and not in a good way. Instead of "Count(Rate) OVER..." I would use "SUM( CASE WHEN Rate IS NULL THEN 0 ELSE 1 END ) OVER..." simply because it explains what we're doing with NULL. I would also include a comment briefly explaining why we're using NULL like that and (more importantly) who made that design decision.

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you for sharing your thoughts. It is a great way for us to learn and grow. Really appreciate your perspective and it is well noted 👍

  • @karthikvenkataram4790
    @karthikvenkataram4790 Жыл бұрын

    Excellent question and excellent solution. Thanks a lot "Learn at Knowstar" for getting these kinds of questions to our knowledge. This channel for SQL is really helping me out for interviews. One doubt is that, should we not use RANK() over (partition by CurrencyKey) in our CTE table clause? Will that still not work? I dont have the editor to try it myself, if someone can try pls let me know. I am trying to install an editor to see it myself, and update here, in case if there is someone who can share some insights to it before then, please do so. Thank youj.

  • @fahadmahmood7150
    @fahadmahmood7150 Жыл бұрын

    Nice explanation.! Very Informative..Thank you..Keep making these kind of videos it really helps us a lot

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Glad it was helpful 🙏

  • @WrongTurn-cz2lu
    @WrongTurn-cz2lu2 ай бұрын

    Very very important concept and in easy to understand way of explaining.

  • @LearnatKnowstar

    @LearnatKnowstar

    Ай бұрын

    Glad it was helpful!

  • @djjiang3718
    @djjiang3718 Жыл бұрын

    Thank you for such an excellent question and solution! Keep up with hard work!

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Glad it was helpful 🙏

  • @hv0032113
    @hv0032113 Жыл бұрын

    Great explanation. Waiting for more videos.

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you. More videos coming soon

  • @yasmeenkarachiwala3766
    @yasmeenkarachiwala37664 ай бұрын

    extremely helpful, great video!!

  • @LearnatKnowstar

    @LearnatKnowstar

    4 ай бұрын

    Glad it was helpful!

  • @kristyowens2284
    @kristyowens2284 Жыл бұрын

    I am aware of one solution using CTE but this is an excellent solution- neat and tidy !

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you 🙏

  • @peak9680
    @peak9680 Жыл бұрын

    Thank you so much for bringing this topic ❤️

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Glad it was helpful

  • @diydecor2653
    @diydecor2653 Жыл бұрын

    Very helpful

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you

  • @MrChilo89
    @MrChilo898 ай бұрын

    Thanks for the video, what if i want to take this for the last not null and apply to evert column of a table?

  • @sravankumar1767
    @sravankumar1767 Жыл бұрын

    Nice explanation 👌 👍 👏

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you 🙏

  • @pradeepmohan4910
    @pradeepmohan49105 ай бұрын

    Nice explanation mam.. Good job keep going ❤

  • @LearnatKnowstar

    @LearnatKnowstar

    5 ай бұрын

    Glad it was helpful.

  • @kingstonxavier
    @kingstonxavier Жыл бұрын

    Thank you! How the First_value() function picking 0.9108? which is the last value in the group since our order by is ascending.

  • @mocanada304
    @mocanada304 Жыл бұрын

    Thank you for the video! It doesn't work if the value if non-numeric. Let's say we have product name which has value only for the first row and has null for the rest until we have another product and the rate for the product. Can you make one video based on the non-numeric values?

  • @satishchaurasia84ya
    @satishchaurasia84ya Жыл бұрын

    Great👍👏

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thanks 😊

  • @srinivasbusi8755
    @srinivasbusi8755 Жыл бұрын

    Very informative not sure why people will not recommend this type of channel

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you for your support !

  • @riddlex
    @riddlex Жыл бұрын

    This is helpful. I was asked an interview question where I had to pair matches between two teams from a set of 10 teams. The pairing should be in a way that the same team shouldn't be paired. For e.g. Team A cannot be paired with team A, and if Team A has been paired with team B, then team B shouldn't be paired with Team A again. To approach this, I used cross join on the same table, and I removed the teams that were the same. However, I was not able to figure out how to keep only A-B paring. My output had both A-B & B-A pairing.

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    We have already covered this scenario in one of our tutorials. You can check it out here - kzread.info/dash/bejne/oWialpWLlM7Ph9I.html Hope it helps!

  • @riddlex

    @riddlex

    Жыл бұрын

    @@LearnatKnowstar Thanks, it totally worked.

  • @vijayvishwakarma2293
    @vijayvishwakarma2293 Жыл бұрын

    Please make video fifo method mutual fumd calculation in SQL

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Sure. We will plan more videos based on these business scenarios soon 👍

  • @Gyan_Hub_
    @Gyan_Hub_ Жыл бұрын

    how can we solve with Case Statement please

  • @vinaya111k
    @vinaya111k Жыл бұрын

    Why do you have partition by Currenykey 2nd time. could we have used partition by Grp only instead of both?

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Since the count is based on the partitioning in currency key, the second grouping would also need the currency key partitioning. The count values for different currency keys can repeat.

  • @sarvesht7299
    @sarvesht7299 Жыл бұрын

    Can you provide the DDLs and insert statements in comments ? It will be very useful for us to practice

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    They are provided in the link in the description. Hope this helps!

  • @sarvesht7299

    @sarvesht7299

    Жыл бұрын

    Thanks

  • @karthikvenkataram4790
    @karthikvenkataram4790 Жыл бұрын

    Hi All, based on my below comment the RANK() or DENSE_RANK does NOT work here because, the RANK() increments values against NULL values in the column. Unfortunately, am unable to share the screenshot here, but I believe you all understand what I mean. Hope this helps. Thank you.

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    Thank you for sharing your doubts and thoughts. It really is helpful for all 👍

  • @karthikvenkataram4790

    @karthikvenkataram4790

    Жыл бұрын

    @@LearnatKnowstar I should thank you infact. Your videos are really really helpful, especially for cracking SQL interviews. I got a lot more benefited. 🙏

  • @peak9680
    @peak9680 Жыл бұрын

    How to implement this logic for columns ,below is an example for same.. Brand 202101 202102 202103. 202104 A. Null. 20. Null. Null Expected output Brand 202101 202102 202103. 202104 A. Null. 20. 20. 20.

  • @LearnatKnowstar

    @LearnatKnowstar

    Жыл бұрын

    You might need to unpivot the data first. Below tutorial on Unpivot might be helpful for you. kzread.info/dash/bejne/n5poo6SpeNTNkco.html

Келесі