案例1:已知c1字段,计算c2和c3字段。
- 数据准备:
drop view test1; create view test1(c1) as values (1),(2),(3); select * from test1;
- 子查询
-- 普通嵌套 select *, c1*c2 as c3 from (select c1, c1+2 as c2 from test1); -- with as with t1 as ( select c1, c1 + 2 as c2 from test1 ), t2 as ( select *, c1 * c2 as c3 from t1 ) select * from t2;
- 临时视图
create temporary view temp_view1 as select c1, c1 + 2 as c2 from test1; create temporary view temp_view2 as select *, c1 * c2 as c3 from temp_view1; select * from temp_view2;
- 永久视图
create view vi