ex25.with
[WITH <Sub Query>] - with ์
SELECT column_list - select ์
FROM table_name - from ์
[WHERE search_condition] - where ์
[GROUP BY group_by_expression] - group by์
[HAVING search_condition] - having ์
[ORDER BY order_expresstion [ASC|DESC]]; - order by์
with์
- ์ธ๋ผ์ธ๋ทฐ(from์ ์๋ธ์ฟผ๋ฆฌ)์ ์ด๋ฆ์ ๋ถ์ด๋ ๊ธฐ์
- ๋จ๋
์ผ๋ก๋ ๋ชป ์. (select๋ฌธ ์์)
with ์์ํ
์ด๋ธ๋ช
as (
๊ฒฐ๊ณผ์
select
)
select ๋ฌธ;
with์ ์คํ ๋ฐฉ์
1. Materialize ๋ฐฉ์ > ์์ ํ
์ด๋ธ์ด 2๋ฒ ์ด์ ์ฌ์ฉ๋๋ฉด ๋ด๋ถ์ ์์ ํ
์ด๋ธ ์์ฑ + ๋ฐ๋ณต ์ฌ์ฌ์ฉ
2. Inline ๋ฐฉ์ > ์์ ํ
์ด๋ธ ์์ฑ์์ด ๋งค๋ฒ ์ธ๋ผ์ธ ์ฟผ๋ฆฌ๋ฅผ ๋ฐ๋ณต ์คํ
select * from (select name, buseo, jikwi from tblInsa where city = '์์ธ');
--์์๋ ๊ฒฐ๊ณผ ๋๊ฐ์
with seoul as (select name, buseo, jikwi from tblInsa where city = '์์ธ')
select * from seoul;
--์ฌ๋ฌ๊ฐ
select *
from (select name, age, couple from tblMen where weight < 90) a
inner join (select name, age, couple from tblWomen where weight > 60) b
on a.couple = b.name;
--with์ ์ฌ์ฉํด์ ์ฌํํ๊ฒ (with ํ๋๋ก ์ฌ๋ฌ๊ฐ์ ์์ํ
์ด๋ธ)
with a as (select name, age, couple from tblMen where weight < 90),
b as (select name, age, couple from tblWomen where weight > 60)
select * from a inner join b on a.couple = b.name;
-- ์์ํจ์ or rownum
-- with์ ์ฌ์ฉํ๋ฉด ํธ๋ฆฌํจ
-- ๊ธ์ฌ 5์
-- ์๋ ๋ฐฉ์
select * from (select
name, buseo, basicpay,
rank() over(order by basicpay desc) rnum
from tblInsa) where rnum = 5;
-- with์ ์ฌ์ฉ
with insa as (
select
name, buseo, basicpay,
rank() over(order by basicpay desc) rnum
from tblInsa
)
select * from insa where rnum = 5;
'ํ๋ก๊ทธ๋๋ฐ ๊ณต๋ถ > Oracle' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ex27] transaction (0) | 2023.03.30 |
---|---|
[ex26] Hierarchical Query (0) | 2023.03.30 |
[ex24] rank (0) | 2023.03.30 |
[ex23] pseudo, rownum (0) | 2023.03.26 |
[ex22] alter (0) | 2023.03.26 |