LeetCode 596: Classes More Than 5 Students [SQL]

  Рет қаралды 4,841

Frederik Müller

Frederik Müller

Күн бұрын

Пікірлер: 12
@YASHKUMARJAIN
@YASHKUMARJAIN 3 жыл бұрын
Great work Frederik. Waiting for more leetcode database content.
@ayeoh47
@ayeoh47 2 жыл бұрын
this is a great problems, i had fun solving it. selecting class with more than 5 students, making a temp table that identifies the student count of each class, running filter on this temp table to derive class with >= 5 students.
@jaimegcia
@jaimegcia 2 ай бұрын
Thank you so much for this man, It really helps. As someone currently looking for a related job, this helps feed my confidence.
@frederikmuller
@frederikmuller 2 ай бұрын
hang in there and good luck with your interviews!
@penumono
@penumono Жыл бұрын
This worked for me SELECT class FROM Courses GROUP BY class HAVING COUNT(class) > 4;
@yuxuan2393
@yuxuan2393 3 жыл бұрын
thanks a lot!
@daniellesong3686
@daniellesong3686 3 жыл бұрын
Hi Frederik, thanks a lot for the tutorial, I'm new to SQL and would like to learn how to count by classes, e.g. how many "Math" appears in the column, and return the class name if the count number is >=5. Looking forward to your feedback. Thanks.
@frederikmuller
@frederikmuller 3 жыл бұрын
Hi Danielle, I'm glad to see you're trying to learn SQL. If you would like to count by classes you could just SELECT class, COUNT(*) FROM table GROUP BY class If you would like to get the count "Math" values only, you could use the following construct: SELECT SUM(CASE WHEN class = "Math" THEN 1 ELSE 0 END) FROM table This will count each occurrence of "Math" as a 1 and everything else as a 0. Calculating the sum of this column will give you the amount of "Math" values in that column. I hope that makes sense!
@daniellesong3686
@daniellesong3686 3 жыл бұрын
@@frederikmuller Hi Frederik, thanks for the prompt reply. It's very helpful. I tried COUNT BY class, the output is as expected. But my mistake is not using DISTINCT student. That makes the submission is not accepted. Note in each problem is very important clue for coding....
@frederikmuller
@frederikmuller 3 жыл бұрын
@@daniellesong3686 I'm glad you found the issue. Right, this problem asks for the number of students per class and not just number of rows per class.
@abhinavkumar6584
@abhinavkumar6584 2 жыл бұрын
can't wee also use class in count ?
@frederikmuller
@frederikmuller 2 жыл бұрын
if there are no duplicate entries, yes. the note in the question mentions the possibility of having duplicates in the table, so using COUNT(DISTINCT student) is best.
LeetCode 197: Rising Temperature [SQL]
8:20
Frederik Müller
Рет қаралды 18 М.
LeetCode 1934: Confirmation Rate [SQL]
12:08
Frederik Müller
Рет қаралды 1,6 М.
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,7 МЛН
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 3,2 МЛН
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 30 МЛН
LeetCode 181: Employees Earning More Than Their Managers [SQL]
8:28
Frederik Müller
Рет қаралды 14 М.
LeetCode 1581: Customer Who Visited but Did Not Make Any Transactions [SQL]
11:52
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 198 М.
What does a Data Analyst actually do? (in 2024) Q&A
14:27
Tim Joo
Рет қаралды 64 М.
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,7 МЛН