LeetCode 1633 Interview SQL Question with Detailed Explanation | Practice SQL

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

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

After grouping by the constest_id and finding the count of user_id we can store it in a cte and then we will find the count of user store it in another cte and then we will cross join between the two cte and then we can find the percentage.

ajaykumargaudo
Автор

# Write your MySQL query statement below

select contest_id, count(*) from Users), 2) as percentage
from Register
group by contest_id
order by percentage desc, contest_id asc

sanketarekar
Автор

select contest_id, round(count(user_id) *100.0 / (select count(user_id) from Users), 2) as percentage from Register
group by 1
order by count(user_id) *100.0 / (select count(user_id) from Users) desc, contest_id asc

expandingourselves
Автор

I thought of this query, please let me know

SELECT r.contest_id,
ROUND((COUNT(DISTINCT(r.USER_ID))*100/COUNT(DISTINCT(u.USER_ID))), 2) as percentage
FROM
REGISTER r,
USERS u
group by contest_id
order by percentage desc, contest_id asc;

swayamsiddharath
Автор

if we need a single varible then we cross join to table too : CREATE TEMPORARY TABLE total_user_count AS SELECT COUNT(*) AS total_count FROM users; -- Use the temporary table in your main query SELECT r.contest_id, ROUND(COUNT(DISTINCT r.user_id) / t.total_count * 100, 2) AS percentage FROM register r CROSS JOIN total_user_count t GROUP BY r.contest_id ORDER BY percentage DESC, , or use a vraible of sql to do this

mickyman
join shbcf.ru