DB/오라클 SQL문

24. ★ update ★| not in | round(avg(age),1) | To_char(ipsaday,'yyyy')='1998' | rollback | commit

DEV-HJ 2022. 2. 22. 14:43
반응형

--직업이 교사이거나 개발자인 사람을 출력하시오
select * from person where job='교사' or job='개발자';
select * from person where job in('교사','개발자');

--직업이 교사, 개발자를 제외한 직업을 가진 사람출력
select * from person where job not in('교사','개발자');

--여자이면서 나이가 30살 이상인 사람출력
select * from person where gender='여자' and age>=30;

--평균나이 구하기
select avg(age) 평균나이 from person;

--평균나이 구하기, 소수점 한자리로
select round(avg(age),1) from person;

--1월에 5월에 입사한 사람 출력
select * from person Where To_char(ipsaday,'mm')='01' or To_char(ipsaday,'mm')='05';

--1998년에 입사한 사람 출력
select * from person Where To_char(ipsaday,'yyyy')='1998';

--person테이블 생성하기
create table person2 as select * from person;

--직업과 나이 전체수정
--update는 자주씀 ★
update person set job='변호사', age='23';

--위에서 잘못 수정한거 되돌리기
rollback; 

--2번만 이름, 직업과 나이 수정 
update person set name='송강', job='변호사', age='23' where num=2;

--임씨이면서 개발자인 사람의 젠더를 '남자'로 변경
update person set gender='남자' where name LIKE '임%' and job='개발자';

--num이 8번인 사람의 직업을 '트레이너'로 변경
update person set job='트레이너', ipsaday='2022-01-01' where num=8;

--저장하기
commit;



반응형