Percentage of Users Attended a Contest | Leetcode 1633 | Crack SQL Interviews in 50 Qs

  Рет қаралды 6,857

Learn With Chirag

Learn With Chirag

Күн бұрын

Пікірлер: 20
@learnwithchirag
@learnwithchirag 10 ай бұрын
Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on Instagram Handles :- @createwithchirag - instagram.com/createwithchirag/ @learn.with.chirag - instagram.com/learn.with.chirag/ LinkedIn: www.linkedin.com/in/chirag-sehgal-9200111b8/ Let's stay connected and keep the creativity flowing! 💡
@arshlankhan1507
@arshlankhan1507 10 ай бұрын
why we did not use right join in this qus ? explain please
@swatiriyal9242
@swatiriyal9242 10 ай бұрын
Easiest solution i could find on internet, Good work sir!
@learnwithchirag
@learnwithchirag 10 ай бұрын
Glad it helped !..Keep Learning 💯🎯
@justcodeitbro1312
@justcodeitbro1312 5 ай бұрын
if we are using group by then it will count the number of user_id in each group right ? no need of distinct worked for me without it
@rishavrajsingh7660
@rishavrajsingh7660 Ай бұрын
hello I'm having one question why you didn't use the join and how its even possible without join function?
@skkrrtt2344
@skkrrtt2344 Ай бұрын
# Write your MySQL query statement below SELECT r.contest_id, ROUND(COUNT(DISTINCT user_id)*100/(SELECT COUNT(user_id) from Users),2) as percentage FROM Users as u RIGHT JOIN Register as r USING(user_id) GROUP BY contest_id ORDER BY percentage DESC,r.contest_id; My solution
@Nik_vlogs1
@Nik_vlogs1 5 ай бұрын
Thanks very helpful
@abhishekdhakne4879
@abhishekdhakne4879 Жыл бұрын
why didn't we use JOIN
@learnwithchirag
@learnwithchirag Жыл бұрын
Yes , There can be multiple ways of solving an SQL question. Here is the query using JOIN- SELECT r.contest_id, ROUND((SUM(IF(r.user_id IS NOT NULL, 1, 0)) / (SELECT count(*) FROM users) * 100), 2) AS percentage FROM Register r LEFT JOIN users u ON u.user_id = r.user_id GROUP BY r.contest_id ORDER BY percentage DESC, r.contest_id ASC; The choice between using a join or not depends on the specific requirements of your query and the structure of your database. Both approaches are valid, and you should choose the one that best fits your needs and performs well with your database schema and data distribution.
@akhilpratapsingh3223
@akhilpratapsingh3223 Жыл бұрын
In this we should use right join na?@@learnwithchirag
@sandhyarawat1768
@sandhyarawat1768 11 ай бұрын
sir (SELECT count(*) FROM users) ki place me count(u.user_name) ya u.user_id likh sakte hai kya???? nahi to kyu nahi
@sandeepvarma89
@sandeepvarma89 11 ай бұрын
​​@@sandhyarawat1768kar sakte hai dono ka answer same hi aayega count (*)from users Kiya toh total rows count honge jo hai 3, user_name count Kiya toh bhi 3 hi aayega,user_id bhi use kar sakte hai
@redeagle6580
@redeagle6580 Жыл бұрын
invalid use of group by de rha
@learnwithchirag
@learnwithchirag 11 ай бұрын
Please do check your syntax again. The query is working perfectly fine for me !
@karunakarverma6467
@karunakarverma6467 4 ай бұрын
TLE mar gya ye to
@muhibajaz7156
@muhibajaz7156 3 ай бұрын
Solve this query with Join: SELECT r.contest_id, ROUND(COUNT(r.user_id) / (SELECT COUNT(*) FROM Users) * 100, 2) AS percentage FROM Register r LEFT JOIN Users u ON u.user_id = r.user_id GROUP BY r.contest_id ORDER BY percentage DESC, r.contest_id ASC;
@abhijaychouhan5176
@abhijaychouhan5176 2 ай бұрын
SELECT contest_id, ROUND(COUNT(contest_id)*100/(SELECT COUNT(user_id) FROM Users), 2) AS percentage FROM Register GROUP BY contest_id ORDER BY percentage DESC, contest_id This code is running fine , even if I changed this "distinct user_id" to "contest_id" and why this code is more optimised HELP ME
LeetCode 1633: Percentage of Users Attended a Contest [SQL]
5:25
Frederik Müller
Рет қаралды 4,5 М.
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 253 М.
Querying 100 Billion Rows using SQL, 7 TB in a single table
9:07
Arpit Agrawal (Elastiq.AI)
Рет қаралды 60 М.
19. Queries Quality and Percentage | SQL Interview Questions and Answers
8:23
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 856 М.
Learn 12 Basic SQL Concepts in 15 Minutes (project files included!)
16:48
LeetCode 1211 Interview SQL Question with Detailed Explanation | Practice SQL
13:28