根据现有的MySQL表创建视图—牛客上的一道题
题目描述:
针对actor表创建视图actor_name_view,只包含first_name以及last_name两列,并对这两列重新命名,first_name为first_name_v,last_name修改为last_name_v:
actor表的建表语句如下:
CREATE TABLE actor (
actor_id smallint(5) NOT NULL PRIMARY KEY,
first_name varchar(45) NOT NULL,
last_name varchar(45) NOT NULL,
last_update datetime NOT NULL);
答案:
创建view,字段就是select查出现成的字段
-- create view [viewname] as [查询语句]
create view actor_name_view
as
select first_name as first_name_v,last_name as last_name_v from actor;
或者
创建view,自己指定字段名
create view actor_name_view(first_name_v,last_name_v)
as
select first_name,last_name from actor;