0% found this document useful (0 votes)
2 views7 pages

Rdbms

The document contains a series of SQL queries focused on analyzing educational data, including teacher lecture counts, student grades, and contact information. It includes operations such as grouping, ranking, and joining tables to extract insights about teachers and students. The queries aim to summarize performance metrics and contact details while filtering and ordering the results based on specific criteria.

Uploaded by

seckinalpkargi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Rdbms

The document contains a series of SQL queries focused on analyzing educational data, including teacher lecture counts, student grades, and contact information. It includes operations such as grouping, ranking, and joining tables to extract insights about teachers and students. The queries aim to summarize performance metrics and contact details while filtering and ordering the results based on specific criteria.

Uploaded by

seckinalpkargi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

WITH teacher_lecture_counts AS (
SELECT
session_prof_ref AS teacher_epita_email,
COUNT(*) AS cnt
FROM
sessions
GROUP BY
session_prof_ref
),
ranked_teachers AS (
SELECT
teacher_epita_email,
cnt,
DENSE_RANK() OVER (ORDER BY cnt DESC) AS rnk
FROM
teacher_lecture_counts
)
SELECT
teacher_epita_email, cnt, rnk
FROM ranked_teachers
ORDER BY rnk ASC, teacher_epita_email ASC;
2.

select s.student_epita_email,
avg(g.grade_score) as average
from grades g
left join students s on g.grade_student_epita_email_ref = s.student_epita_email
group by s.student_epita_email
order by average desc, student_epita_email asc;

3.

select
c.contact_email,
c.contact_birthdate,
s.student_epita_email
from students s
join contacts c
on s.student_contact_ref = c.contact_email
order by c.contact_birthdate desc,
s.student_epita_email asc;

4.

select
contact_email,
contact_first_name,
contact_city,
contact_address
from contacts
where contact_city = 'New York' order by contact_email asc;

5.

SELECT
c.contact_email,
c.contact_birthdate,
s.student_epita_email,
TIMESTAMPDIFF( YEAR,
c.contact_birthdate,
CURDATE( ) )
AS age from contacts c join students s
on c.contact_email = s.student_contact_ref
order by c.contact_birthdate desc limit 5;

6.

select
contact_email,
contact_first_name,
contact_city
from contacts
order by contact_city asc,
contact_email asc limit 10;

7.

select
s.student_epita_email,
avg(g.grade_score) as average from grades g
join students s on g.grade_student_epita_email_ref = s.student_epita_email
where s.student_enrollment_status in ("confirmed", "completed")
group by s.student_epita_email
order by average desc, student_epita_email asc;

8.

SELECT
teacher_epita_email
FROM
teachers
WHERE
teacher_epita_email NOT IN (
SELECT DISTINCT session_prof_ref
FROM sessions
)
ORDER BY
teacher_epita_email ASC;

9.
select
attendance_course_ref,
count(attendance_presence) as missing_attendance
from attendance
where attendance_presence = 0
group by attendance_course_ref
order by missing_attendance desc;

10.

WITH student_averages AS (
SELECT
s.student_epita_email,
s.student_population_code_ref AS program_code,
AVG(g.grade_score) AS avg_grade
FROM
grades g
INNER JOIN students s ON g.grade_student_epita_email_ref =
s.student_epita_email
WHERE
s.student_population_year_ref = 2021
GROUP BY
s.student_epita_email, s.student_population_code_ref
),
highest_per_program AS (
SELECT
program_code,
student_epita_email,
avg_grade,
RANK() OVER (PARTITION BY program_code ORDER BY avg_grade DESC)
AS rnk
FROM
student_averages
)
SELECT
program_code,
student_epita_email
FROM
highest_per_program
WHERE
rnk = 1
ORDER BY
avg_grade DESC,
program_code ASC,
student_epita_email ASC;

You might also like