SQL Tutorial 18: Write a query to Find Top 3 Students by Average Grade

SQL Tutorial 18: Write a query to Find Top 3 Students by Average Grade

327 Lượt nghe
SQL Tutorial 18: Write a query to Find Top 3 Students by Average Grade
Watch the entire SQL playlist here: https://www.youtube.com/playlist?list=PL_neLGJ5LPUzPIg96tf7rXb57D6-3n5Pq In this video, we tackle a complex database problem involving table creation (CREATE), data insertion (INSERT), and advanced querying (JOIN, AVG, ORDER BY) to find the top 3 students based on average grades! 🔹 What You’ll Learn: ✅ How to design a relational database with CREATE TABLE ✅ Inserting sample data with INSERT INTO ✅ Using JOIN, AVG(), and ORDER BY to find top students ✅ Writing efficient SQL queries for data ranking Challenge: Try solving it yourself before checking the solution! Comment your answers below. Don't forget to like, subscribe, and hit the bell icon for more SQL challenges & coding tutorials! Schema & Sample Data: CREATE TABLE Students_table ( student_id INT PRIMARY KEY, name VARCHAR(100), age INT ); CREATE TABLE Courses ( course_id INT PRIMARY KEY, course_name VARCHAR(100), credits INT ); CREATE TABLE Enrollments ( enrollment_id INT PRIMARY KEY, student_id INT, course_id INT, grade DECIMAL(5,2), FOREIGN KEY (student_id) REFERENCES Students_table(student_id), FOREIGN KEY (course_id) REFERENCES Courses(course_id) ); INSERT INTO Students_table (student_id, name, age) VALUES (1, 'Alice Johnson', 22), (2, 'Bob Smith', 21), (3, 'Charlie Brown', 23), (4, 'David Williams', 22), (5, 'Eva Adams', 20); INSERT INTO Courses (course_id, course_name, credits) VALUES (101, 'Mathematics', 3), (102, 'Physics', 4), (103, 'Computer Science', 3), (104, 'History', 2); INSERT INTO Enrollments (enrollment_id, student_id, course_id, grade) VALUES (1, 1, 101, 90.5), (2, 1, 102, 88.0), (3, 1, 103, 92.0), (4, 2, 101, 85.0), (5, 2, 102, 89.5), (6, 3, 103, 95.0), (7, 3, 104, 87.0), (8, 4, 101, 78.0), (9, 4, 102, 82.0), (10, 5, 103, 80.0), (11, 5, 104, 75.5); -- Expected Output: -- name avg_grade -- Charlie Brown 91.00 -- Alice Johnson 90.17 -- Bob Smith 87.25 Follow me on LinkedIn: https://www.linkedin.com/in/paragtech/ Relevant Hastags: #SQL #Database #SQLQuery #SQLInterview #LearnSQL #DataScience #SQLChallenge #SQLTutorial #SQLForBeginners #SQLQueries #SQLServer #MySQL #PostgreSQL #SQLPractice #SQLDeveloper #CodingChallenge #TechInterview #DataAnalytics #SQLExercises #Programming #SoftwareDevelopment