0% found this document useful (0 votes)
2 views

SQL Grouping and Aggregation DT

СЉЛ задачи

Uploaded by

Sofija Arnaudova
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Grouping and Aggregation DT

СЉЛ задачи

Uploaded by

Sofija Arnaudova
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Grouping and Aggregation

1. Count of Learners Who Have Not Started Any Course


Show the total number of learners who have a completion percentage of 0 for
all their courses.

SELECT COUNT(LearnerID) AS TotalLearners, CompletionPercentage


FROM Progress
GROUP BY CompletionPercentage
HAVING CompletionPercentage=0

2. Learners Who Completed All Their Courses


List the full names of learners who have 100% completion in all their enrolled
courses.

SELECT Learners.FullName, Progress.CompletionPercentage


FROM Learners
JOIN Progress ON Learners.LearnerID=Progress.LearnerID
WHERE Progress.CompletionPercentage=100
3. Courses with the Lowest Completion Rate
Identify the courses with the lowest average completion percentage.

SELECT TOP 3(Courses.CourseID), Courses.CourseName,


AVG(Progress.CompletionPercentage) AS AvgCompletionPercent
FROM Progress
JOIN Courses ON Progress.CourseID=Courses.CourseID
GROUP BY Courses.CourseName, Courses.CourseID
ORDER BY AVG(Progress.CompletionPercentage) ASC

4. Average Duration of Courses with Learners Enrolled


Calculate the average duration of courses where at least one learner is
enrolled.

SELECT Courses.CourseID, Courses.CourseName, AVG(Courses.Duration) AS


AvgCourseDuration
FROM Courses
LEFT JOIN Progress ON Courses.CourseID=Progress.CourseID
LEFT JOIN Learners ON Progress.LearnerID=Learners.LearnerID
GROUP BY Courses.CourseName, Courses.CourseID
ORDER BY AVG(Progress.CompletionPercentage)
OR, I tried the below query with subqueries, but I am doing something wrong,
I won’t get a result:
SELECT CourseID, AVG(Duration) AS AvgDuration
FROM Courses
WHERE CourseID IN(
SELECT CourseID
FROM Progress
GROUP BY CourseID
HAVING COUNT(LearnerID)>=1)

5. Top 3 Courses by Average Completion


Show the top 3 courses with the highest average completion percentage.

SELECT TOP 3(Courses.CourseID), Courses.CourseName,


AVG(Progress.CompletionPercentage) AS AvgCompletionPercent
FROM Progress
JOIN Courses ON Progress.CourseID=Courses.CourseID
GROUP BY Courses.CourseName, Courses.CourseID
ORDER BY AVG(Progress.CompletionPercentage) DESC

You might also like