To identify records where both a guest and a property made their first booking simultaneously, use window functions with RANK() partitioned by guest ID and listing ID respectively, then filter for records where both rankings equal 1, and count these matching records.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
MakeMyTrip SQL Interview Question | 16/100 SQL Interview Tips #shortsHinzugefügt:
Welcome to the 16th video of SQL interview tips and this question was asked in MakeMyTrip. So, save, share, and follow to learn effectively. This input two tables, users and the users booking, count the reservations where it was both the guest's very first booking and the listing's very first booking.
Listing means the property. So, here if you look at this data and question, this table does not comes into picture as you look at the data. So, for this particular guest ID, which is two, the very first booking this guy made, it was on the 1st of August in 2011. And if you look at this listing ID, means the property itself, the 10 and 10, first booking for this property was made on this particular day itself, where this guest also made its very first booking. So, eventually this is going to be the valid record for the counting. This record, where guest ID is three and the property is 30, means the ID for this one is 30. So, this is the only record where the guest three also made the first booking and this property ID also had its first booking on this.
So, this is how we are getting the total output as two here. How we are going to solve it because question says that you need to identify something where it was the first booking of guest and it was the first booking for the property itself. We are going to solve it with the help of the window function. So, what our logic is, first what we can do, we can generate the ranking keeping the guest ID in the partition by and the booking time stamp in the order. So, it will generate the ranking for the particular guest itself when he made the first booking. So, that booking will be ranked one.
Similarly, we are generating another column and deriving the ranking for the listing or the property, keeping the listing ID in the partition by and the particular booking time stamp in the order by. This way, with this particular window function, we are able to identify the first booking made for each property ID or listing ID. This is how the intermediate data will look like. You can see for this particular guest, okay? For this particular guest itself, this guest made the first booking on this time stamp, that's why guest ranking is one. And if you take this two all together and arrange the date, so this will come on the top, that is why list ranking is also one. And in the final query, this is what exactly we are doing, finding out those records where the guest ranking and list ranking is equal and we are simply taking the count of it. If you want to solve this level of SQL interview questions, then do check out my platform Grok Data Skills.
I have already created something for you.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











