--복습문제
--Q1. 교수명 전공과목
select p.name 교수명, d.dname 전공과목
from professor p, department d
where p.major=d.deptno;
--Q2. 학년별 평균키와 최저몸무게를 구하시오
select grade, avg(height), min(weight)
from student
GROUP BY grade;
--Q3. 동일한 직무(job)을 가진 사원의 수를 구하시오
--단 평균급여가 2000이상만 조회할것
select job 직무, count(empno)
from emp
GROUP BY job
having avg(sal)>=2000;
--Q4. 조인+서브쿼리
--student테이블과 department 테이블을 사용해서 오나라 학생과 1전공이 동일한 학생들의 이름을 조회하시오
--오나라 유아교육 으로 조회할듯
select s.name "학생이름", d.dname "1전공명"
from student s, department d
where s.deptno1=d.deptno
and s.deptno1=(select deptno1 from student where name='오나라');
--Q5. professorr에서 입사일이 바비교수님보다 나중에 입사한 교수들의
--이름과 입사일, 학과명을 출력하라
--홍길동 1990-01-01 문헌정보학과
select p.name 이름, p.hiredate 입사일, d.dname 학과명
from professor p, department d
where p.major=d.deptno
and hiredate>(select hiredate from professor where name='바비');
--Q6. student 테이블에서 1전공이 101번인 학과의 평균몸무게 보다
--몸무게가 많은 학생들의 이름과 몸무게를 출력하시오
--서진수 문헌정보학과 68
select s.name 이름, d.dname 학과, s.weight 몸무게
from student s, department d
where d.deptno=s.deptno1
and weight>(select avg(weight) from student where deptno1=101);
'DB > 오라클 SQL문' 카테고리의 다른 글
26. 조인, 외부키 문제 (0) | 2022.02.24 |
---|---|
26. Join & Foreign key 복습 | 부모테이블 | 자식테이블 (0) | 2022.02.24 |
25. ★ 시퀀스 | 테이블 | 상품추가 | primary key | CONSTRAINT | REFERENCES | 조인 방법 3개 ★ (0) | 2022.02.23 |
25. CONSTRAINT | check 제약조건 생성, 삭제 | L999,999,999 | UNIQUE (0) | 2022.02.23 |
25. 조인 (가상테이블) | 조인 문제 5개 | 비등가조인 (0) | 2022.02.23 |