Advanced SQL: WINDOW Function Explained - Difference b/w ROW_NUMBER, RANK & DENSE_RANK Leetcode 1112

preview_player
Показать описание
Welcome to the first episode of our groundbreaking series designed to take your SQL skills to the next level! In this series, we're tackling 50 of the most challenging and insightful interview questions on #advanced SQL, aimed at transforming you from an intermediate user to a bona fide #sql expert. Whether you're preparing for a job #interview , seeking to enhance your data manipulation capabilities, or simply passionate about mastering the complexities of SQL, this series is your ultimate roadmap.

SQL Schema:
Create table If Not Exists Enrollments (student_id int, course_id int, grade int)
Truncate table Enrollments
insert into Enrollments (student_id, course_id, grade) values ('2', '2', '95')
insert into Enrollments (student_id, course_id, grade) values ('2', '3', '95')
insert into Enrollments (student_id, course_id, grade) values ('1', '1', '90')
insert into Enrollments (student_id, course_id, grade) values ('1', '2', '99')
insert into Enrollments (student_id, course_id, grade) values ('3', '1', '80')
insert into Enrollments (student_id, course_id, grade) values ('3', '2', '75')
insert into Enrollments (student_id, course_id, grade) values ('3', '3', '82')

Pandas Schema:
data = [[2, 2, 95], [2, 3, 95], [1, 1, 90], [1, 2, 99], [3, 1, 80], [3, 2, 75], [3, 3, 82]]
enrollments = pd.DataFrame(data, columns=['student_id', 'course_id', 'grade']).astype({'student_id':'Int64', 'course_id':'Int64', 'grade':'Int64'})

In this first episode, we kick things off with a deep dive into a question that stumps many aspiring SQL professionals. We'll explore the intricacies of advanced query writing, focusing on techniques that go beyond the basics of SELECT statements and WHERE clauses. You'll learn about advanced joins, window functions, recursive queries, and much more.

What to Expect:

Detailed Explanations: We don't just solve the question; we dissect it. You'll understand not only the 'how' but also the 'why' behind each solution, ensuring you can apply these principles to a variety of SQL challenges.
Step-by-Step Approach: Our tutorials are designed to be easy to follow. We break down complex concepts into manageable parts, making advanced SQL more accessible than ever.
Real-World Applications: These aren't just theoretical exercises. Each question is selected for its relevance to real-world SQL problems, ensuring you gain practical skills that you can apply in a professional setting.
Interactive Learning: Engage with the content through quizzes and challenges presented throughout the series. Test your knowledge, practice new skills, and solidify your understanding of advanced SQL techniques.
Community Support: Join a growing community of SQL enthusiasts and professionals. Share insights, ask questions, and receive feedback through the comments section below each video.

Why This Series?

SQL remains one of the most in-demand skills in the tech industry, and for a good reason. It's the backbone of data analysis, database management, and many forms of programming. As data continues to drive decision-making in businesses worldwide, the ability to manipulate and retrieve data efficiently becomes increasingly valuable. This series is designed to equip you with these skills, ensuring you're not just ready for your next job interview but also prepared to tackle real-world data challenges.

Who Should Watch?

Intermediate SQL users looking to advance their skills.
Job seekers preparing for technical interviews.
Data professionals seeking to deepen their understanding of SQL.
Anyone with a passion for data and an eagerness to learn.
How to Get the Most Out of This Series:

Practice Along: Have your SQL environment ready to try out each question as we go through them.
Engage: Leave comments with your own solutions, questions, or insights.
Stay Consistent: Follow the series for a comprehensive understanding of advanced SQL.

Subscribe and Join Us on This Journey
Рекомендации по теме
Комментарии
Автор

I have been watching ur videos when u have 1k subscribers hatsoff to ur consistency, I switched to other company with 100% hike thanks .

gajendragada_dynamites
Автор

WITH CTE AS (
SELECT
STUDENT_ID,
COURSE_ID,
GRADE,
RANK() OVER (PARTITION BY STUDENT_ID ORDER BY GRADE DESC, COURSE_ID ASC) AS RNK
FROM ENROLLMENTS
)
SELECT STUDENT_ID, COURSE_ID, GRADE
FROM CTE
WHERE RNK = 1;

IMAJAY
Автор

WITH cte AS
(SELECT *, DENSE_RANK() OVER(PARTITION BY student_id ORDER BY grade DESC) AS rank FROM Enrollments)
SELECT * FROM cte GROUP BY student_id; this also works right

kattamanchithulasiram
Автор

WITH CTE AS (SELECT *,
ROW_NUMBER() OVER (PARTITION BY student_id ORDER BY grade DESC) AS RN
FROM ENROLLMENTS)
SELECT student_id, course_id, grade
FROM CTE
WHERE RN = 1
ORDER BY student_id ;

PodcastTalkzz
Автор

why join, when Select student_id, min(course_id), max(grade) as grad from Enrollments
group by student_id
order by student_id
works fine

Simran_
Автор

Oracle SQL
-- Drop the table if it exists
DROP TABLE Enrollments;

-- Create the Enrollments table
CREATE TABLE Enrollments (
student_id INT,
course_id INT,
grade INT
);

-- Truncate the table to remove any existing data (if needed)
TRUNCATE TABLE Enrollments;

-- Insert data into the Enrollments table
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (2, 2, 95);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (2, 3, 95);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (1, 1, 90);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (1, 2, 99);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (3, 1, 80);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (3, 2, 75);
INSERT INTO Enrollments (student_id, course_id, grade) VALUES (3, 3, 82);

IMAJAY
visit shbcf.ru