首页 > 试题广场 >

创建一个actor_name表

[编程题]创建一个actor_name表
  • 热度指数:134506 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
对于如下表actor,其对应的数据为:
actor_id first_name last_name last_update
1 PENELOPE GUINESS 2006-02-15 12:34:33
2 NICK WAHLBERG 2006-02-15 12:34:33

请你创建一个actor_name表,并且将actor表中的所有first_name以及last_name导入该表.
actor_name表结构如下,题目最后会查询actor_name表里面的数据来对比结果输出
列表 类型 是否为NULL 含义
first_name varchar(45) not null 名字
last_name varchar(45) not null 姓氏
示例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');

输出

PENELOPE|GUINESS
NICK|WAHLBERG
create table if not exists actor_name
(
    first_name varchar(45) not null comment '名字',
    last_name varchar(45) not null comment '姓氏'
)
select first_name,last_name from actor;
发表于 2024-06-05 20:09:23 回复(0)
create table actor_name
(
    first_name varchar(45) primary key comment '名字' not null,
    last_name varchar(45) comment'姓氏' not null
);
insert into actor_name
select first_name,last_name
from actor;
为什么存在“primary key"答案就不对呀
编辑于 2024-04-16 15:50:51 回复(0)
create table actor_name
(
    first_name varchar(45) not null comment '名字',
    last_name varchar(45) not null comment '姓氏'
);
insert into actor_name
(select first_name,last_name from actor);

编辑于 2024-02-06 00:44:16 回复(0)
-- 检查
drop table if exists actor_name;
-- 建表
create table actor_name
(
    first_name varchar(45)	not null comment '名字',
    last_name varchar(45)	not null comment '姓氏'
);
-- 通过select拆入
insert into actor_name
select first_name,last_name from actor

发表于 2023-11-26 18:36:37 回复(0)
一、
create table if not exists actor_name as select first_name, last_name from actor
二、
create table  if not exists actor_name(first_name varchar(45) not null comment'名字' ,last_name varchar(45) not null comment'姓氏');
insert into actor_name(first_name,last_name) select first_name,last_name from actor;


发表于 2023-10-25 11:29:44 回复(0)
create table actor_name as 
select 
    first_name,
    last_name
from
    actor 

/*   或者先建表,再插入数据
create table actor_name(
                        first_name varchar(45) not null comment '名字',
                        last_name varchar(45) not null comment '姓氏'
                        );

insert into actor_name
select 
    first_name,
    last_name
from 
    actor;
*/

发表于 2022-12-11 12:00:32 回复(0)
方法一:
create table actor_name(
    first_name varchar(45not null,
    last_name  varchar(45not null
);
insert into actor_name select first_name,last_name from actor;

方法二:
create table actor_name(
    first_name varchar(45not null,
    last_name  varchar(45not null
as select first_name,last_name from actor;


发表于 2022-10-14 16:38:15 回复(0)
create table if not exists actor_name
as
select first_name, last_name
from actor
发表于 2022-09-13 23:52:16 回复(0)
CREATE TABLE  IF NOT EXISTS actor_name (
    first_name VARCHAR(45) NOT NULL COMMENT '名字',
    last_name  VARCHAR(45) NOT NULL COMMENT '姓氏'
);
INSERT INTO actor_name(
SELECT first_name, last_name
FROM actor);
 注意插入数据的一种写法。
发表于 2022-09-06 09:24:05 回复(0)
create table actor_name as
select
  first_name,
  last_name
from
  actor
发表于 2022-08-07 12:56:06 回复(0)
create table actor_name (
first_name varchar(45) not null comment '名字',
last_name  varchar(45) not null comment '姓氏'  
);
insert into actor_name 
select first_name, last_name 
FROM actor
发表于 2022-08-06 20:28:58 回复(0)
create table actor_name 
(first_name	varchar(45)	not null comment'名字',
 last_name	varchar(45)	not null comment'姓氏'
) select 
first_name,last_name
from actor

发表于 2022-05-15 17:44:40 回复(0)
create table actor_name(
frist_name varchar(45) not null comment '名字',
last_name varchar(45)  not null comment '姓氏'
                        );
insert into actor_name
select first_name,last_name from actor;

发表于 2022-04-14 09:45:06 回复(0)
怎么提交不了啊
发表于 2022-03-28 10:22:35 回复(0)
create table if not exists actor_name(select first_name,last_name from actor)
发表于 2022-03-27 12:51:18 回复(0)
create table actor_name
as select first_name, last_name from actor;

发表于 2022-03-17 16:33:13 回复(0)
create table actor_name
(first_name varchar(45) not null comment "名字",
 last_name varchar(45) not null comment "姓氏");
insert into actor_name values ("PENELOPE", "GUINESS"), ("NICK", "WAHLBERG");

发表于 2022-03-11 21:39:45 回复(0)
并没有想当然的 FROM关键字:

# # 错误
# CREATE TABLE actor_name
# FROM (SELECT first_name, last_name
#       FROM actor)

# 正解
CREATE TABLE actor_name
SELECT first_name, last_name
FROM actor


发表于 2022-02-12 03:38:30 回复(0)

问题信息

难度:
43条回答 13978浏览

热门推荐

通过挑战的用户

查看代码