LeetCode Medium 1355 IBM Interview SQL Question with Detailed Explanation

preview_player
Показать описание

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

Simple Solution:with cte as (select activity, count(*) as cnt from friends
group by activity)
select activity from cte
where cnt not in(select max(cnt) from cte)
and cnt not in(select min(cnt) from cte)

muddassirnazar
Автор

with cte as
(select activity, count(id) as cnt
from friends group by 1 )

select activity from cte
where cnt NOT IN ( Select max(cnt) from cte ) and cnt NOT IN ( Select min(cnt) from cte )

expandingourselves
Автор

with data as (
select *, count(f.id) over(partition by a.activity order by a.id) as cnt
from Friends f join Activities a on f.activity_id=a.id )

select a.activity from data where cnt range between (min(cnt)+1) and (max(cnt)-1)

yashnikhare
Автор

can i use this Please let me know

with cte as
(
Select activity, count(id) as num_part from Friends
group by activity)
Select activity from cte
where num_part>(select min(num_part) from cte) and num_part<(select max(num_part) from cte)

vijaygupta
Автор

WITH activity_counts AS (
SELECT
activity,
COUNT(*) AS count
FROM
Friends
GROUP BY
activity
)
SELECT
activity AS results
FROM
activity_counts
WHERE
count != (SELECT MAX(count) FROM activity_counts)
AND count != (SELECT MIN(count) FROM activity_counts);

mickyman
Автор

WITH activity_counts AS (
SELECT
activity,
COUNT(*) AS count,
MAX(COUNT(*)) OVER () AS max_count,
MIN(COUNT(*)) OVER () AS min_count
FROM
Friends
GROUP BY
activity
)
SELECT
activity AS results
FROM
activity_counts
WHERE
count != max_count
AND count != min_count;

mickyman
welcome to shbcf.ru