본문 바로가기

Database/MS-SQL

오픈과제 02.doc 33번~

반응형





use study_exam2

SELECT * ---- 33번
FROM 
Student, MAJOR -- student=부모, major= 자식
WHERE student.MajorCode = 1 AND
major.majorCode =1

SELECT * FROM --33번
Student AS s, Major AS m
WHERE s.MajorCode = m.MajorCode AND -- 네츄럴 조인
m.MajorName='컴퓨터공학과'

SELECT * FROM --33번
Student AS s INNER JOIN Major AS m
ON s.MajorCode = m.MajorCode AND -- 이너조인
m.MajorName='컴퓨터공학과'

SELECT * ----- 34번
FROM
student, major
WHERE student.majorcode= 2 AND
major.majorcode=2

SELECT * FROM STUDENT A, MAJOR B    -- 34번
WHERE A.MajorCode = B.MajorCode AND B.MajorCode = '02'


//////////////////////   35번 문제  /////////////////////






-- 35번 문제
SELECT s.name, ssub.subjectcode, sub.SubjectName
FROM student AS s, student_subject AS ssub , subject AS sub
WHERE s.sno=0727001

--  1
SELECT *
FROM
student AS a, student_subject AS B
WHERE a.sno = 0727001
--  2
SELECT *
FROM
student AS a, student_subject AS B
WHERE a.sno = b.sno
AND a.sno = 0727001
--  3
SELECT a.name, b.subjectcode
FROM
student AS a, student_subject AS B
WHERE a.sno = b.sno
AND a.sno = 0727001
--  4
SELECT a.name, b.subjectcode, c.subjectname
FROM
student AS a, student_subject AS B , subject AS c
WHERE a.sno = b.sno

AND b.subjectcode = c.subjectcode
AND a.sno = 0727001


-- 이너조인
SELECT a.name, b.subjectcode, c.subjectname
FROM student AS a INNER JOIN student_subject AS B 
ON a.sno= b.sno INNER JOIN subject AS c
ON b.subjectcode = c.subjectcode
WHERE a.sno = 0727001