0% found this document useful (0 votes)
14 views2 pages

Lab 2

lab 2 database 7th edition

Uploaded by

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

Lab 2

lab 2 database 7th edition

Uploaded by

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

1.

SELECT dept_name
FROM (
SELECT dept_name, SUM(salary) AS value
FROM instructor
GROUP BY dept_name
) AS dept_total,
(
SELECT AVG(salary_sum) AS avg_value
FROM (
SELECT SUM(salary) AS salary_sum
FROM instructor
GROUP BY dept_name
) AS salary_totals
) AS dept_total_avg
WHERE dept_total.value >= dept_total_avg.avg_value;

2. SELECT course_id, sec_id, year, semester, COUNT(*) AS num


FROM takes
GROUP BY course_id, sec_id, year, semester
HAVING COUNT(*) = (SELECT MAX(cnt)
FROM (SELECT COUNT(*) AS cnt
FROM takes
GROUP BY sec_id, course_id, year, semester) AS max_count);

3 .SELECT student.ID, student.name, takes.course_id


FROM student
INNER JOIN takes ON student.ID = takes.ID;

4.SELECT student.ID
FROM student
LEFT OUTER JOIN takes ON student.ID = takes.ID
WHERE takes.ID IS NULL;

5. SELECT s.ID
FROM student s
LEFT JOIN advisor a ON s.ID = a.s_id
WHERE a.s_id IS NULL OR a.i_ID IS NULL;
6. CREATE VIEW tot_credits AS
SELECT t.year, SUM(c.credits) AS num_credits
FROM takes t
INNER JOIN course c ON t.course_id = c.course_id
GROUP BY t.year;

You might also like