You are on page 1of 2

Assignments

SQL Simple Queries November 10th 2022

SportsClub:

1. Return all male minors of the sportsClub that have a parent in the club and are not yet adult (<18
year old).
SELECT * FROM `memtra` WHERE `gender`="m" AND `isChildFK`IS NOT NULL AND `age`<18 and
isMember=1;

2. How many courses does the sportsClub offer per area?


SELECT `area`, count(*) as “Amount” FROM `course` group by `area`;

3. List the areas that offer at least 3 courses or more.


SELECT `area`, count(*) as "Amount" FROM `course` group by `areaFK` having count(*) >=3;

4. How old is the oldest and how old is the youngest member – return the ages of the oldest and
youngest member.
SELECT min(`age`) as "Youngest Member", max(`age`) as "Oldest Member" FROM `memtra`;

5. Return name, age and parent name of the youngest Club Member
SELECT `memName` as 'Name of youngest member',`isChildOf` as 'Parent of youngest member',
`age`
FROM `memtra`
WHERE `age` =
(select min(`age`) from memtra)

6. Return for each course the number of member enrollments that the course has. (How many
participants does each course have)
select `courseID`, count(*) as 'Number of participants'
from enrollment group by `courseID` order by count(*) desc;

7. How many trainers work in the Club?


SELECT count(*)as "Number of Trainers" FROM `trainer` ;

8. How are NULL values treated when grouping?


How many courses does each trainer teach? (Make sure that there is at least one course without a
trainer)
SELECT `trNameFK`, count(*)as "Number of Courses" FROM `course`group by `trNameFK`order by
count(*) desc;
University:

9. How many contact hours does each lecturer teach?


SELECT `lecturer`, sum(`contactHours`) as "Contact Hours" FROM `course` group by `lecturer`
order by sum(`contactHours`) DESC;

10. How many students take courses (at all)?


SELECT distinct `stud.ID` from enrollment order by `stud.ID`asc;

11. Which students take only 1 course?


SELECT `stud.ID`, count(*) as "Number of courses" FROM `enrollment` group by `stud.ID` having
count(*)=1;

You might also like