--hive中有一张真实的基础表t_usa_covid19 select * from itcast.t_usa_covid19;
--1、创建视图 createview v_usa_covid19 asselect count_date, county,state,deaths from t_usa_covid19 limit5;
--能否从已有的视图中创建视图呢 可以的 createview v_usa_covid19_from_view asselect * from v_usa_covid19 limit2;
--2、显示当前已有的视图 showtables; show views;--hive v2.2.0之后支持
--3、视图的查询使用 select * from v_usa_covid19;
--能否插入数据到视图中呢? --不行 报错 SemanticException:A view cannot be used as target table for LOAD or INSERT insertinto v_usa_covid19 select count_date,county,state,deaths from t_usa_covid19;
--4、查看视图定义 showcreatetable v_usa_covid19;
--5、删除视图 dropview v_usa_covid19_from_view;
--6、更改视图属性 alterview v_usa_covid19 set TBLPROPERTIES ('comment' = 'This is a view');
--7、更改视图定义 alterview v_usa_covid19 asselect county,deaths from t_usa_covid19 limit2;
createview techops_employee asselect firstname, lastname, ssn from userinfo where department = 'java';
--使用视图优化嵌套查询 from ( select * from people join cart on(cart.pepople_id = people.id) where firstname = 'join' )a select a.lastname where a.id = 3;
--把嵌套子查询变成一个视图 createview shorter_join as select * from people join cart on (cart.pepople_id = people.id) where firstname = 'join'; --基于视图查询 select lastname from shorter_join whereid = 3;