LeetCode 1633: Percentage of Users Attended a Contest [SQL]

preview_player
Показать описание
Solution and walkthrough of leetcode database problem 1633: Percentage of Users Attended a Contest. I'm using MySQL but this solution should work in any SQL dialect such as PostgreSQL SQL Server, etc.

Playlists:

Рекомендации по теме
Комментарии
Автор

I like the way he thinks
1. get the feilds you want to print out
2.see what are they showing without any filter
3.then filter the things and check the output again
4/now use the output to get the result

although looks likes an obvious approach at first but if didn't applied and if directly faced the problem head on then it starts looking tough/complex but by his method it is easier to breakdown the problem, so more than sql he's teaching to breakdown the problem in chunks

mickyman
Автор

Thanks,
Before this tutorial i had no clue we can use subquery in "Select" statement like that also.
Can you suggest any article which tell us more about this type of subquery usage in select Statement

YASHKUMARJAIN
Автор

just 2 line !!! great
select contest_id, round(count(user_id) * 100.0/(select count(user_id) from users), 2) as percentage
from register
group by contest_id
order by percentage desc, contest_id
when i try this, Time Limit Exceeded

Aravindkumar-bp
Автор

Why should we use subquery instead of 3😮

BonnyLee-cm