LeetCode Interview SQL Question with Detailed Explanation | Practice SQL | LeetCode 619

preview_player
Показать описание
Previous Video: LeetCode 613 Shortest Distance Between Points

In this video I solve and explain a 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 is about finding the biggest single number and also includes points to keep in mind to develop SQL queries. You will also learn about COMMON TABLE EXPRESSIONS and CASE WHEN THEN statements.

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
Рекомендации по теме
Комментарии
Автор

This also get accepted
with cte as
(select num
from mynumbers
group by num having count(num) = 1) select max(num) as num from cte;

AmanAshutoshBCS
Автор

My approach:
select max(num) as num from (select num from MyNumbers group by num having count(num)<=1)

keerthikakj
Автор

max(num) returns maximum value if present.
If not it returns NULL.

I hope the case statement is not needed here.
select max(num) from cte is simply enough.

meenayegan
Автор

SELECT CASE WHEN count(*)>0 THEN max(num) ELSE NULL END AS num
FROM
mynumbers
WHERE num NOT IN
(SELECT num
FROM
mynumbers
GROUP BY num
HAVING count(num) >1)

imdeepu
Автор

My approach:

with cte as(
select num, count(*) as freq
from MyNumbers
group by num
)

select max(num) as num
from cte
where freq=1
order by num

sauravchandra
Автор

A more direct approach :

select num
from mynumbers
group by num
having count(*) =1
order by num desc
limit 1;

abhisheksharma
Автор

Can't we do like...

Select max(distinct num) group by num having count(num) =1;

abhinavtiwari
Автор

we could use select distinct on number and havinng ma(number) or number = null

vasunova
Автор

with cte as (select num from mynumbers group by num having count(num)=1)
select max(num) as num from cte;

payalvaishnav
Автор

Use distinct number max number can we use na

creativetrends
Автор

Another approach
SELECT
CASE
WHEN COUNT(num) > 0 THEN num
else 'null'
END AS num
FROM
mynumbers
GROUP BY num
HAVING COUNT(num) = 1
ORDER BY num DESC
LIMIT 1;

Ilovefriendswebseries
Автор

Select max(n.num) as num from (select num from MyNumbers Group by MyNumbers Group by num
Having count(num) =1) as n;

-Joshna
Автор

Easy SQL Solution

WITH CTE AS(
SELECT num, COUNT(*) count_of_number
FROM MyNumbers
GROUP BY num)

SELECT MAX(num)
FROM CTE
WHERE count_of_number = 1

NeelShaho
Автор

SELECT CASE WHEN COUNT(num) = 1 THEN num ELSE NULL END AS num
FROM MyNumbers
GROUP BY num
ORDER BY num DESC
LIMIT 1;

placementpreparation