列表

详情


SQL232. 针对actor表创建视图actor_name_view

描述

针对actor表创建视图actor_name_view,只包含first_name以及last_name两列,并对这两列重新命名,first_name为first_name_v,last_name修改为last_name_v:
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);

后台会插入2条数据:
insert into actor values ('1', 'PENELOPE', 'GUINESS', '2006-02-15 12:34:33'), ('2', 'NICK', 'WAHLBERG', '2006-02-15 12:34:33');
然后打印视图名字和插入的数据

示例1

输入:

drop table if exists 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);
insert into actor values ('1', 'PENELOPE', 'GUINESS', '2006-02-15 12:34:33'), ('2', 'NICK', 'WAHLBERG', '2006-02-15 12:34:33');

输出:

['first_name_v', 'last_name_v']
PENELOPE|GUINESS
NICK|WAHLBERG

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3304KB, 提交时间: 2021-05-28

create view  actor_name_view  as select first_name as first_name_v ,last_name as last_name_v from actor

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3484KB, 提交时间: 2021-08-09

create view actor_name_view(first_name_v,last_name_v) as
select first_name,last_name from actor;

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3172KB, 提交时间: 2021-04-18

create view actor_name_view(first_name_v,last_name_v) as 
select first_name, last_name
from actor;

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3192KB, 提交时间: 2020-10-30

create view actor_name_view (first_name_v,last_name_v) as
select 
first_name
,last_name
from actor
  

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3192KB, 提交时间: 2020-10-30

create view actor_name_view as 
select first_name as first_name_v,last_name as last_name_v from actor;

上一题