No video

LeetCode Medium 585 "Investments in 2016" Twitter Interview SQL Question With Detailed Explanation

  Рет қаралды 4,476

Everyday Data Science

Everyday Data Science

Күн бұрын

Question: leetcode.com/p...
In this video I solve and explain a medium difficulty leetcode SQL question using MySQL query. This question has been asked in Apple, Facebook, Amazon, Google, Adobe, Microsoft, Adobe interviews or what we popularly call FAANG interviews.
I explain the related concept as well. This question includes points to keep in mind to develop SQL queries.
LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.
If you found this helpful, Like and Subscribe to the channel for more content.
#LeetCodeSQL #FAANG #SQLinterviewQuestions

Пікірлер: 22
@vikashkumargupta4876
@vikashkumargupta4876 2 ай бұрын
The explanation was very clear and so in-depth which helped me to understand the concepts very clearly specially the table creation and providing knowledge on that. Thanks and keep up the good work. We all are thankful😊
@adnanafdalahmed
@adnanafdalahmed 2 ай бұрын
kzfaq.info/get/bejne/iZZgmMiossvWd2g.html
@23cash86
@23cash86 Ай бұрын
Very good explanation
@sougaaat
@sougaaat 2 ай бұрын
there's an easy way to do it -> # Write your MySQL query statement below with inv as (select tiv_2015 from insurance group by 1 having count(tiv_2015) > 1), pol as ( select min(pid) as pid from insurance group by concat(lat, ",", lon) having count(concat(lat, ",", lon)) = 1 ) select round(sum(tiv_2016),2) as tiv_2016 from insurance where tiv_2015 in (select tiv_2015 from inv) and pid in (select pid from pol)
@sonalibabar
@sonalibabar 11 ай бұрын
Another way using windows function: # Write your MySQL query statement below WITH cte AS( SELECT i.* , COUNT(i.pid) OVER(PARTITION BY i.tiv_2015) same_tiv_2015 , COUNT(i.pid) OVER(PARTITION BY i.lat,i.lon) same_loc FROM Insurance i ) SELECT ROUND(SUM(tiv_2016),2) AS tiv_2016 FROM cte WHERE same_tiv_2015 > 1 AND same_loc = 1 ;
@shreehari2589
@shreehari2589 2 ай бұрын
Awesome explanation bro, keep up the good work
@snehasoni1392
@snehasoni1392 7 ай бұрын
select round(sum(tiv_2016),2) as tiv_2016 from Insurance where tiv_2015 IN ( select tiv_2015 from insurance group by tiv_2015 having count(*) >1 ) AND(lat,lon) IN ( select lat,lon from insurance group by lat , lon having count(*)= 1 )
@yongcui1308
@yongcui1308 Жыл бұрын
so clear, great explanation!
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found the video useful 😊
@sanyagandhi6576
@sanyagandhi6576 Жыл бұрын
Awesome explanation! Thank you😊
@AJ-sw5hx
@AJ-sw5hx 10 күн бұрын
how come pid no 2 during joins only one row is there? why isn't it joined with row no 1,3,4?
@EUEC_CHARRUNETHRACR
@EUEC_CHARRUNETHRACR 11 ай бұрын
Best explanation ever!! Hats off, Sir !! I tried with my own as a beginner, Sir. I have a small doubt with my code. WITH cte AS (SELECT CONCAT(lat, ',' , lon) AS location FROM Insurance GROUP BY lat, lon HAVING COUNT(pid) > 1) SELECT ROUND(SUM(tiv_2016),2) AS tiv_2016 FROM Insurance GROUP BY tiv_2015 HAVING COUNT(pid) > 1 AND (CONCAT(lat, ',' , lon) NOT IN (SELECT location FROM cte)) Runtime Error Unknown column 'lat' in 'IN/ALL/ANY subquery' Why this code shows run time error, Sir? Would you please explain, so that it might improve my learning, sir ?
@nitinmadan4009
@nitinmadan4009 3 ай бұрын
(CONCAT(lat, ',' , lon) NOT IN (SELECT location FROM cte)). . In your code, here seems to be an extra ' (' and an extra ')' at the end and entire line seems to be enclosed under concat therefore. Instead it should be AND CONCAT(lat, ',' , lon) NOT IN (SELECT location FROM cte)
@AI-ew1rj
@AI-ew1rj Ай бұрын
why do a left join and not an inner join here?
@rupdeepthey
@rupdeepthey Жыл бұрын
Best!
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found the video useful 😊
@alfabinomial6183
@alfabinomial6183 Жыл бұрын
HAVING COUNT(pid) > 1 i did not understand here.. can u please explain it again !
@suba_sah
@suba_sah Жыл бұрын
It perplexed me too! I believe its working as if having(*) > 1; to find the duplicates
@pranjal-barnwal
@pranjal-barnwal 11 ай бұрын
Basically first we found out the locations which are repeated using this count clause, so to be excluded later using the 'not in'
@nitinmadan4009
@nitinmadan4009 3 ай бұрын
@@suba_sah since pid is the primary key for the table, we can use count(pid) as primary key column ensures no duplicate records
@harshavardhanreddy1318
@harshavardhanreddy1318 2 жыл бұрын
Bro please do problem number 1097 in leetcode I am not getting answer
@rishavkumar4939
@rishavkumar4939 2 жыл бұрын
Have you taken the leetcode subscription?
The Giant sleep in the town 👹🛏️🏡
00:24
Construction Site
Рет қаралды 21 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 3,8 МЛН
Whoa
01:00
Justin Flom
Рет қаралды 50 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 37 МЛН
585. Investments in 2016 - LeetCode SQL Solution
10:08
Code with Carter
Рет қаралды 910
LeetCode Medium 1341 "Movie Rating" SAP Interview SQL Question with Explanation
12:04
What does a Data Analyst actually do? (in 2024) Q&A
14:27
Tim Joo
Рет қаралды 50 М.
SQL Interview Problem asked during Amazon Interview
15:15
techTFQ
Рет қаралды 23 М.
LeetCode 534: Game Play Analysis III [SQL]
8:44
Frederik Müller
Рет қаралды 5 М.
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 355 М.
The Giant sleep in the town 👹🛏️🏡
00:24
Construction Site
Рет қаралды 21 МЛН