DB/오라클 SQL문

26. 어제 복습 문제

DEV-HJ 2022. 2. 24. 10:18
반응형

--복습문제
--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);

반응형