10.06.08 DB 수업

Study/Oracle 2011. 9. 3. 23:51
6월8일

문제1. 은행에 예금과 대출이 모두 잇는 고객을 찾아라
select distinct cnm
from borrower
where cnm in
(select cnm
from depositor);

문제2. 은행에 대출은 있으나 예끔은 없는 모든 고객을 찾아라.

select distinct cnm
from borrower

where cnm not in
(select cnm 
from depositor);

문제3. Perryridge 지점에 예금과 대출을 모두 가진 고객을 찾아라.
select distinct cnm
from borrower, loan
where borrower.lnr=loan.lnr and bnm = 'Perryridge' 
and cnm in (select cnm
from depositor, account
where depositor.anr = account.anr
and bnm = 'Perryridge');

문제4. Brooklyn에 위치한 어떤 지점보다 더 많은 자산을 가진 모든 지점을 찾아라.

select distinct t.bnm
from branch as t, branch as s
where t.assets > s.assets and
s.bc = 'Brooklyn';

문제5. Brooklyn에 위치한 어떤 지점보다 더 많은 자산을 가진 모든 지점을 찾아라.(1.some 2.all)사용


select distinct bnm
from branch
where assets > some
(select assets
from branch
where bc = 'Brooklyn');

select distinct bnm
from branch
where assets > all
(select assets
from branch
where bc = 'Brooklyn');


문제6. Brooklyn에 위치한 모든 지점에 예금이 있는 고객을 찾아라.

select distinct s.cnm
from depositor as s
where not exists(
(select bnm
from branch
where bc = 'Brooklyn')
except
(select r.bnm
from depositor as t, account as r
where t.anr = r.anr and
s.cnm = t.cnm));
*except = - (차 기능임)


----문제7. Perrydige 지점에 하나의 계좌만 가진 모든 고객을 찾아라.----

select t.cnm
from depositor as t
where unique (select r.cnm
from account, depositor as r
where t.cnm = r.cnm and
r.anr = account.anr and
account.nbm='Perryridge')

유니크 인식않함 pass
------------------------------------------------------------------

문제8. 평균 예금 잔고가 500불을 초과하는 지점들의 평균 예금 잔고를 찾아라.

select bnm, balance
from (select bnm, avg(balance)
from account
group by bnm)
as result (bnm, balance)
where balance > 500
 
은행예제DB(2010-1).hwp

'Study > Oracle' 카테고리의 다른 글

10.05.26 DB 실습  (0) 2011.09.03
10.05.04 DB 실습  (0) 2011.09.03
10.04.28 DB 실습  (0) 2011.09.03
10.06.01 DB 수업  (0) 2011.09.03
10.05.26 DB 수업  (0) 2011.09.03
Posted by 코딩하는 야구쟁이
,