Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 1

LAB04

HUỲNH TRỌNG TIẾN-DE150396


USE FUH_UNIVERSITY
--1.Find all those students who were born in 1990
select * from tblStudent where year(stuBirthDate) = '1990'
--2.Find all those instructor who lead the subject named 'Introduction to database'
--in the 3rd semester of 2010 school year
select i.insName
from tblInstructor i left join tblSection s
on i.insSSN = s.insSSN where secYear = 2010
and s.secSemester = 1
and s.subCode in (select subCode
from tblSubject
where subName = 'Introduction to
database')
--3.Find all courses that the student named 'Lê Nguyễn Hoài An' has taken in 2010 school year

SELECT su.subName
from tblSection se left join tblSubject su
on se.subCode = su.subCode
where se.secYear = 2010
and se.secSemester in (select claCode
from tblStudent
where stuName =
N'Lê Nguyễn Hoài An')
--4.Find the number of students for each class
select claCode, count(claCode) as Total from tblStudent group by claCode
--5.Find all students who passed all courses that he/she has taken in 2010 school year
SELECT stu.*
FROM tblStudent stu, tblReport rp, tblSection sec
WHERE stu.stuCode=rp.stuCode
AND rp.secCode=sec.secCode
AND sec.secYear=2010
EXCEPT
SELECT stu.*
FROM tblStudent stu, tblReport rp, tblSection sec
WHERE stu.stuCode=rp.stuCode
AND rp.secCode=sec.secCode
AND sec.secYear=2010
AND rp.repStatus='R'
--6

--7
SELECT c.subName AS 'Course Name', COUNT(stuCode) AS 'Retake Students'
FROM tblSection a, tblReport b, tblSubject c
WHERE a.secCode = b.secCode
AND a.secYear = 2010
AND b.repStatus = 'R'
AND a.subCode = c.subCode
GROUP BY c.subName

You might also like