Тёмный

Remove Redundant Pairs - SQL Interview Query 1 | SQL Problem Level "HARD" 

techTFQ
Подписаться 329 тыс.
Просмотров 105 тыс.
50% 1

Опубликовано:

 

22 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 199   
@malcorub
@malcorub 6 месяцев назад
I love the idea! I will be tuning in every day this month.... even on weekends with hangover. LOL
@techTFQ
@techTFQ 6 месяцев назад
Thats the spirit 😃
@somnathdutta6311
@somnathdutta6311 6 месяцев назад
@@techTFQ Don't give the ans in same video. give ans in next video. It will be more helpful. It will also create a hook for your next video and a short of competition as well.
@umangbhatnagar1415
@umangbhatnagar1415 5 месяцев назад
@@somnathdutta6311 Why making things tough. Let it be easy. We are not as good as you. The video's purpose is to help community who is still in its very crude form.
@Useruse867
@Useruse867 3 месяца назад
@@somnathdutta6311 no one will ever watch as there are many channels who solve and give answer there.
@VijayKumar-ec3dz
@VijayKumar-ec3dz 5 месяцев назад
Hi sir, My solution is kind of similar as below with cte as (select *,case when custom1=custom3 and custom2=custom4 then 1 when custom1custom3 or custom2custom4 then 2 else 3 end as r from t1) select * except(r,rn) from (select *,row_number() over(partition by r,year order by year) as rn from cte) a where coalesce(case when r=1 then rn=1 else null end,1=1)
@mindlessscroll
@mindlessscroll 5 месяцев назад
With rm as (select *, IF(STRCMP(brand1,brand2) > 0, concat(brand1,brand2,year), concat (brand2,brand1,year)) as con from brands ), rm1 as( select *, row_number() OVER(PARTITION BY con order by con ) as id from rm) select brand1, brand2, year from rm1 where id=1 or (custom1 custom3 and custom2 custom4)
@gauravtanwar8886
@gauravtanwar8886 4 месяца назад
as per the 3rd condition you need a little adjustment in your code (custom1 custom3 OR custom2 custom4)*
@gauravtanwar8886
@gauravtanwar8886 4 месяца назад
but thanks to your answer i got to know about STRCMP
@rahuldey4730
@rahuldey4730 6 месяцев назад
Loved the question Sir. Even if I was not able to solve this at my own but after I saw the solution and the logic behind this I am speechless and amazed. This is the type of content we need.
@ganeshsundarachary3239
@ganeshsundarachary3239 6 месяцев назад
Awesome , Great learning Experience. Pls make more such challenges.
@ContentRoomB
@ContentRoomB 2 месяца назад
I'm finally done with query 1 with your solution help. looking forward to cracking future questions on my own
@chahatjain3745
@chahatjain3745 6 месяцев назад
with cte as (Select *, row_number() over(partition by Case when brand1>brand2 then CONCAT(brand1,brand2,year) else CONCAT(brand2,brand1,year) end order by year) as rn from brands) Select * from cte rn where rn=1 or (custom1 custom3 and custom2 custom4)
@inderpanda1
@inderpanda1 6 месяцев назад
In my opinion at least out of 30 question first 5 should have been Easy to Medium Level. It seems to be hard and complex for me. The questions should have been from only 1 function among these CTE, Case, Subquery, etc
@amlansasmal
@amlansasmal 6 месяцев назад
same brother:)
@dataengineeringsimplified1049
@dataengineeringsimplified1049 3 месяца назад
with tbl as ( SELECT *,case when brand1
@37_om
@37_om Месяц назад
This is somewhat more clear i think
@shwetamishra1497
@shwetamishra1497 6 месяцев назад
Very helpful . Thank you so much big bro for this series, just keep continue.🙏
@aarizaziz4380
@aarizaziz4380 6 месяцев назад
Thank you very very very much for this initiative. Looking forward to a multi decade event by you just like this! You are one of the best instructors I have come across internet for SQL. hats off to you for taking time to educate us and building the community.
@junaidmahmud2894
@junaidmahmud2894 6 месяцев назад
Great solution. I'm afraid I am a bit late to start but I will definitely continue this!
@khushboobaghel6594
@khushboobaghel6594 6 месяцев назад
Thankyou for guiding for 30 days it will help us to improove Sql.
@ShubhamGautam-k1k
@ShubhamGautam-k1k 5 месяцев назад
we can put union as well in place of or, and case statements for the conditions in place of Row_num window function, rest is same.
@vishalmaurya3008
@vishalmaurya3008 6 месяцев назад
❤ 30days of sql >>>>75 days of 😊 hard चैलेंज 😅 Thank you sir that is extremely amazing❤❤❤❤❤❤❤
@CricketLivejavwad
@CricketLivejavwad 6 месяцев назад
Techtfq is back💯😎 We all are excited.
@beautifulworld3976
@beautifulworld3976 6 месяцев назад
It is informative from the problem statement we get idea how to solve thank you so much it is helpful for me this 30 days i will become still more strong in SQL database
@kalpeshispatil
@kalpeshispatil 6 месяцев назад
You are simply amazing buddy... I am user CTE many times, but not as you shown.. Fan of yours... ❤❤ Will be tuning daily.. Your first example has cracked and shown us where we land in DB queries... Thank You For Us Efforts
@MwAVlogs
@MwAVlogs 6 месяцев назад
I am new in this field, but like the way you explain. It is a complex one I know but still after practicing I’ll get it.
@piyushnautiyal6271
@piyushnautiyal6271 6 месяцев назад
amazing que and the way of solving is awesome.. thank u so much techTFQ!!
@Hsalz
@Hsalz 6 месяцев назад
Simply amazing. Thanks, Thoufiq!
@ritika29
@ritika29 5 месяцев назад
Thanks, it was Helpful 👍 Quick question, what if there was a row with NULL in brand1 column Example: INSERT INTO brands VALUES ( NULL,'lava', 2020, 5, 9, NULL, NULL);
@andreanlobo7373
@andreanlobo7373 6 месяцев назад
extremely insightful.. thanks
@pavanigoud98
@pavanigoud98 6 месяцев назад
Please also doo the sql interview questions for data analyst. Lots of love ❤
@padhenamit
@padhenamit 6 месяцев назад
Thank you for your amazing lectures and feedbacks and thank you for being so supportive!
@Dopamine.Moments
@Dopamine.Moments 6 месяцев назад
You are helping me a lot to build my understanding about SQL, Thanks to you I have cleared most of the interviews by watching and following you. I will be turning in for this series. 😊
@pinkfloyd2642
@pinkfloyd2642 6 месяцев назад
Subscribed right away. Great content. Can't wait to watch more of your videos this weekend itself.
@sabmelegarebaba1233
@sabmelegarebaba1233 6 месяцев назад
Bro pz upload 2 video per day 😊
@yi-lehung6311
@yi-lehung6311 6 месяцев назад
still the best SQL video!!!! I love this idea, please continue!
@splendidabhi
@splendidabhi 6 месяцев назад
Excited to kick off the #30DaySQLQueryChallenge with Query #1! Let's sharpen those SQL skills together and ace those interview queries. Can't wait to see what we'll learn throughout this challenge! 💻💡
@techTFQ
@techTFQ 6 месяцев назад
Amazing 😍
@NEHAKHANZODE-p8p
@NEHAKHANZODE-p8p 2 месяца назад
Thank you for explaining thoroughly :-)
@fathimafarahna2633
@fathimafarahna2633 6 месяцев назад
Amazing 🔥🎉
@techTFQ
@techTFQ 6 месяцев назад
Glad you like it!
@sriharidhanakshirur9245
@sriharidhanakshirur9245 6 месяцев назад
Intresting Question! Im sure if anyone deligently follow this #30DaysSQLChallenge his/her SQL skills drastically improves
@haleylearn
@haleylearn 4 месяца назад
For condition: For pairs of brands in the same year ---> if custom1 != custom3 OR custom2 != custom4 : then keep both pairs Why is it (custom1 custom3 AND custom2 custom4) NOT is (custom1 custom3 OR custom2 custom4) ?
@AJBeiza
@AJBeiza 20 часов назад
I had same question, I think just an error. Output is the same in this case but given other entries the output would be different
@12Patni
@12Patni 5 месяцев назад
Thoufiq Mohammed Thank you for the thorough explanation. The problem's difficulty level is high. Below is my solution: I utilized others columns in the Partition By clause, ensuring accurate row numbering without the need for an additional where clause condition. ;with CTE AS ( Select * , case when brand1 < brand2 then CONCAT(brand1,brand2,year) else CONCAT(brand2,brand1,year) end as Brand from [Asif_SQL].[dbo].[brands] ), CTE_RN AS ( SELECT * , ROW_NUMBER () OVER (PARTITION BY BRAND,CUSTOM1,CUSTOM2,CUSTOM3,CUSTOM4 ORDER BY BRAND ASC ) AS RN FROM CTE ) SELECT brand1,brand2,year,custom1,custom2,custom3,custom4 FROM CTE_RN WHERE RN = 1
@shabbiransari9731
@shabbiransari9731 3 месяца назад
What will you do if the brand is of equal length?
@MuhammedSavadkv
@MuhammedSavadkv 5 месяцев назад
Great. Thank you
@mkgeidam
@mkgeidam 6 месяцев назад
Thanks you Sir, it really helpful
@VivekKBangaru
@VivekKBangaru 5 месяцев назад
Awesome TFQ
@manirahofred801
@manirahofred801 5 месяцев назад
This was really helpful. However, if the dataset was too big and brand records were many & different, I don't think "case when" functionality would be helpful. At the moment because of the dataset we have, that would be the easiest way!
@thirupathinaidusomineni
@thirupathinaidusomineni 6 месяцев назад
with cte_check as ( select *, case when (custom1custom3 and custom2custom4) or custom1 is null or custom2 is null or custom3 is null or custom4 is null then 1 when brand1 = LEAD(brand2) over(order by year) and LEAD(brand1) over(order by year)=brand2 and year = LEAD(year) over(order by year) and (custom1=custom3 and custom2=custom4) then 2 end as dd from brands ) select brand1,brand2,year,custom1,custom2,custom3,custom4 from cte_check where dd in (1,2)
@HimanshuSingh-cf7wr
@HimanshuSingh-cf7wr 6 месяцев назад
My Approach:- select BRAND1,BRAND2,year,Custom1,Custom2,Custom3,Custom4 from (select case when rk=2 and Custom1==custom3 and custom2==custom4 then 1 else 0 end as duplicate_entry,p.* from (select row_number() over (partition by common_name,year order by Brand1) as rk,k.* from (select *,concat(greatest(BRAND1,BRAND2),least(BRAND1,BRAND2)) as common_name from input_table)k)p)o where duplicate_entry1 order by BRAND1
@prithvirajpatil7388
@prithvirajpatil7388 6 месяцев назад
Good question❤ starting it from today.
@ramakrishnatirumala428
@ramakrishnatirumala428 5 месяцев назад
super videos bro...keep posting
@johnsonrajendran6194
@johnsonrajendran6194 6 месяцев назад
Love the way you teach ❤
@khushbu3025
@khushbu3025 6 месяцев назад
Really, It's very nice 🙂 Thank you for this series.
@poojahr5670
@poojahr5670 6 месяцев назад
My Solution with Cte as (Select *, Row_Number() over () as id ,case when Custom1=Custom3 and custom2=custom4 then 1 else 0 end as Type from brands) Select T1.brand1,T1.brand2,T1.year,T1.custom1,T1.custom2,T1.custom3,T1.custom4 from Cte T1 join Cte T2 on T1.brand1 =T2.brand2 Where T1.id
@koushikdey100
@koushikdey100 6 месяцев назад
Great !!, Thank you
@ManishChauhan-fb7uz
@ManishChauhan-fb7uz 6 месяцев назад
with cte as ( select * , row_number() over(partition by id order by id) as rn from ( SELECT * , case when brand1 > brand2 then concat(brand1, brand2, year) else concat(brand2, brand1, year) end as id , case when custom1 = custom3 or custom2 = custom4 then 1 else 0 end as flag FROM brands ) as t ) select * from cte where rn = 1 or (rn > 1 and flag = 0)
@Itsourfamilys
@Itsourfamilys 5 месяцев назад
Thank you so much for SQL videos
@livelovelaugh4050
@livelovelaugh4050 6 месяцев назад
Thank you so much for starting this series. 🙏
@nehalmaheshwari1999
@nehalmaheshwari1999 Месяц назад
@techTFQ Shouldn't the custom1 of one of the row be compared with the custom3 of the other row having same airID instead of the same row?
@abhishekkukreja6735
@abhishekkukreja6735 4 месяца назад
Awesome, Can you share excel page : it's good to store the results and everthing in excel
@pavankumar-cw2sx
@pavankumar-cw2sx 6 месяцев назад
@techTFQ Can we give OR condition instead of AND in WHERE condition at final query like as: where rn = 1 or (custom1 custom3 OR custom2 custom4); ????????????????
@vamshijiguru7636
@vamshijiguru7636 2 месяца назад
select brand1,brand2,year,custom1,custom2,custom3,custom4 from ( select *, row_number ()over (partition by chg,custom1,custom3) rn From (select* , coalesce(case when custom1 = custom3 and custom2 = custom4 then 1 when custom1 != custom3 OR custom2 != custom4 then 0 end,0) chg from brands)a)a where rn =1
@sateeshbabu5792
@sateeshbabu5792 3 месяца назад
Awesome video. do you have video on sql performance ? if yes could you please share.
@NikhilRaj-sd4xm
@NikhilRaj-sd4xm 10 дней назад
Here is my Solution: -- Define the first CTE to calculate the next brand values WITH cte AS ( SELECT *, LEAD(brand2, 1, NULL) OVER (PARTITION BY year ORDER BY year) AS next_brand, LEAD(brand1, 1, NULL) OVER (PARTITION BY year ORDER BY year) AS next_brand1 FROM brands ), -- Define the second CTE to categorize each row cte2 AS ( SELECT *, CASE WHEN brand1 = next_brand AND brand2 = next_brand1 AND custom1 = custom3 AND custom2 = custom4 THEN 'group' ELSE 'not a group' END AS GroupType FROM cte ) -- Select rows where GroupType is 'not a group' SELECT brand1, brand2, year, custom1, custom2, custom3, custom4 FROM cte2 WHERE GroupType = 'not a group'; Please suggest if it is a good solution or not?
@mohdtoufique3786
@mohdtoufique3786 6 месяцев назад
Thanks a lot for the content.. WITH PAIRS AS( SELECT *,CASE WHEN brand1
@sourabroy7787
@sourabroy7787 6 месяцев назад
great initiative and quality content 👍
@Venkatesh-bs7kb
@Venkatesh-bs7kb 6 месяцев назад
Thanks a lot for the video. the way you explain CTE's are awesome!! in your solution line number 20, as per problem statement, it should be an OR condition ryt ? ('or (custom1 custom3 OR custom2 custom4)')
@snehajajodia75
@snehajajodia75 Месяц назад
WITH cte1 as(SELECT * ,CASE WHEN brand1
@sweetysweetyvghb
@sweetysweetyvghb 3 месяца назад
I couldn't solve myself, but I find it easy after seeing the solution..not sure y.
@The-Patil
@The-Patil Месяц назад
I believe below query will give the same result. Select * from brands where custom1=custom3 and custom2=custom4 fetch first 1 row UNION select * from brands where custom1 != custom3 or custom2 != custom4 UNION Select * from brands where custom3 is null or custom4 is null
@navaneeth6414
@navaneeth6414 6 месяцев назад
Great! video Thanks
@techTFQ
@techTFQ 6 месяцев назад
Glad you liked it!
@HarshaV44
@HarshaV44 6 месяцев назад
Thank you so much. little modified : WITH CTE AS ( SELECT * , ROW_NUMBER() OVER (PARTITION BY CASE WHEN brand1 < brand2 THEN CONCAT (brand1,brand2,year) ELSE CONCAT (brand2,brand1,year) END ORDER BY (SELECT NULL)) as RKNO FROM brands ) SELECT * FROM CTE WHERE RKNO = 1 or (custom1 custom3 and custom2 custom4)
@zeeshanahmed2594
@zeeshanahmed2594 6 месяцев назад
Great modification! I think in where clause it should be OR in place of AND.
@haleylearn
@haleylearn 4 месяца назад
SELECT DISTINCT LEAST(brand1, brand2) AS brand1, GREATEST(brand1, brand2) AS brand2, custom1, custom2, custom3, custom4, year FROM brands
@hrishiAOL
@hrishiAOL 2 месяца назад
Can you suggest online SQL editor for practice?
@khushboobaghel6594
@khushboobaghel6594 6 месяцев назад
Thankyou Sir
@srinubathina7191
@srinubathina7191 6 месяцев назад
Thank You sir
@sandydsa
@sandydsa 6 месяцев назад
Fantastic 🌻🌻🌻
@venkateshmallisetty4196
@venkateshmallisetty4196 6 месяцев назад
it is very tipical to download the data set could you please help me with that
@aswinc4829
@aswinc4829 6 месяцев назад
Thank you,it really helps
@riyatiwari4767
@riyatiwari4767 6 месяцев назад
Can you please make video on how to write dynamic query in pyspark. That would be a lot of help. Thank u❤
@jollymeelubari9045
@jollymeelubari9045 6 месяцев назад
Thanks for this
@jayavinayak2593
@jayavinayak2593 6 месяцев назад
Thank You
@techTFQ
@techTFQ 6 месяцев назад
You're welcome
@vishisbest
@vishisbest 6 месяцев назад
This was pretty interesting
@nointernet...1800
@nointernet...1800 6 месяцев назад
Nice video
@ananth.r5317
@ananth.r5317 6 месяцев назад
Thanks lots..❤❤❤❤
@harinadhbabu309
@harinadhbabu309 Месяц назад
hi taufiq, Your videos are helping me alot, but your blog has not been opening for last few days. Please do needfull
@sandeepkumarsingh7981
@sandeepkumarsingh7981 6 месяцев назад
Hi Tafiq, I'm also your huge friend, and your technic is always help to improve my skill. I saw the solution and the logic behind this I am speechless and amazed. This is the type of content we need. thanks you so much. Hey Tofiq, I have downloaded you content but that file is blank. please help me on that.....
@priyankapatil6835
@priyankapatil6835 6 месяцев назад
big thanks techTFQ
@cosmicball4888
@cosmicball4888 5 месяцев назад
but how it check the condition custom1=custom3 and custom2-=custom4 ?
@MrYeduguri
@MrYeduguri 6 месяцев назад
Hello Thoufiq.. Thank you so much for sharing great content. Are you offering online training for sql & plsql?
@sivakrishnasriram4782
@sivakrishnasriram4782 6 месяцев назад
Thank You😊.
@phamnguyentrucgiang569
@phamnguyentrucgiang569 6 месяцев назад
​ @techTFQ Hi, thanks for uploading useful videos. I want to ask: this is easy, medium or hard question?
@teawithbaety
@teawithbaety Месяц назад
While using concat () in MySql why am I getting NULL for pair_id?
@SwarajLandge-c7f
@SwarajLandge-c7f Месяц назад
use this code ---just change case condition with cte1 as( select *, case when brand1
@teawithbaety
@teawithbaety Месяц назад
@@SwarajLandge-c7f okay. Thanks for your help!
@ahmedjassimameenco
@ahmedjassimameenco 6 месяцев назад
thanks
@ManiKandan-kg5ky
@ManiKandan-kg5ky 6 месяцев назад
Waiting bro
@lakshitgupta5064
@lakshitgupta5064 6 месяцев назад
What if after creating the pairid, we just perform groupby operation based on pairid, custom1, custom2, custom3 and custom4 and then filter it by using having count = 1? Will this approach work?
@AbhishekPandey-c8o
@AbhishekPandey-c8o 6 месяцев назад
i was waiting for this
@armaqanalibabaei6980
@armaqanalibabaei6980 4 месяца назад
Hi May I ask a question?even thou you have filtered where rn = 1; , I still see one rn=2 in that column why?
@smrutiranjansenapati1695
@smrutiranjansenapati1695 6 месяцев назад
Hi, Since it has example of 5-6 records, when we have large amount of records, how we can mak sure that the 1st condition if custom1 = custom3 & custom2 = custom4 will not be satisfied to eliminate the duplicate? Please reply. Thank you
@surabhijagadish5210
@surabhijagadish5210 5 месяцев назад
Made complex query too easy.
@karangupta_DE
@karangupta_DE 6 месяцев назад
with cte as ( select *, case when custom1 = custom3 and custom2 = custom4 then 'match' else 'not_matched' end as is_match, row_number()over(order by (select null)) as rn, row_number()over(partition by year order by (select null)) as rn_1 from brands ), cte1 as ( select *, (rn - rn_1) as pair from cte ) select min(brand1) as brand1, max(brand2) as brand2, max(year) as year, max(custom1) as custom1, max(custom2) as custom2, max(custom3) as custom3, max(custom4) as custom4 from cte1 where is_match = 'match' group by pair union all select brand1, brand2, year, custom1, custom2, custom3, custom4 from cte1 where true and is_match != 'match';
@jjayeshpawar
@jjayeshpawar 6 месяцев назад
with cte as (select *, case when brand1 < brand2 then brand1||''||brand2||''|| year else brand2||''||brand1||''|| year end as pair from brands) select brand1,brand2,year,custom1,custom2,custom3,custom4 from ( select *, case when custom1 = custom3 then row_number() over(partition by pair) else dense_rank() over(partition by pair) end as rkk from cte) where rkk = 1
@saitejamanchi1389
@saitejamanchi1389 6 месяцев назад
I think you should also add custom2 = custom4 in the condition in the case clause but very cool idea though!
@Shruti_Gore
@Shruti_Gore 4 месяца назад
Can you make 30 days sql easy to hard playlist
@tornado9689
@tornado9689 6 месяцев назад
My question is you can also select query with column name what you have done in last to fetch the data . What is the need of using cte then
@codeduel
@codeduel 6 месяцев назад
For Optimization sake
@pathanfirozkhan5503
@pathanfirozkhan5503 6 месяцев назад
Amazing video sir, Thanks for your time
@shristisrivastava1324
@shristisrivastava1324 6 месяцев назад
How will you know when to use CTE by looking at the question, sir?
@manvendramingwal8696
@manvendramingwal8696 4 месяца назад
how about 100 days of database series,from 0 to 100 making people perfect in DB, i would like to join.
@nadimatlanagesh1951
@nadimatlanagesh1951 6 месяцев назад
My approach: SELECT brand1,brand2,YEAR,custom1,custom2,custom3,custom4 FROM ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY CASE WHEN brand1 < brand2 THEN brand1||brand2||YEAR WHEN brand2 < brand1 THEN brand2||brand1||YEAR end ORDER BY year) rn FROM brands a WHERE a.custom1=a.custom3 AND a.custom2=a.custom4 ) WHERE rn=1 union SELECT brand1,brand2,YEAR,custom1,custom2,custom3,custom4 FROM brands a WHERE nvl(a.custom1,0)nvl(a.custom3,0) AND nvl(a.custom2,0)nvl(a.custom4,0) ;
@prithvipampana1492
@prithvipampana1492 6 месяцев назад
Bro @malcorub what if brand1 and brand2 length is same
Далее
How to Install and Use an Adjustable TV Arm
00:18
Просмотров 3,6 млн
How to Install and Use an Adjustable TV Arm
00:18
Просмотров 3,6 млн