牛客网-SQL专项训练14
①通过子查询的方式从衬衫表SHIRTABLE中选取出销售单价shirt_price高于全部衬衫的平均价格的衬衫名字:B
解析:
题目要求需要用到子查询,故排除AC选项,而D选项在where子句中使用了聚合函数。
解析:
ALTER TABLE命令用于添加、删除或者更改现有数据表中的列。(alter修改表的结构,update修改表的数据)
- 1.添加列
alter table 表名 add column 列名 类型 【first|after 字段名】; - 2.修改列的类型或约束
alter table 表名 modify column 列名 新类型 【新约束】; - 3.修改列名
alter table 表名 change column 旧列名 新列名 类型; - 4.删除列
alter table 表名 drop column 列名; - 5.修改表名
alter table 表名 rename 【to】 新表名; -
6.如果表已存在,设置默认值alter table 表名 modify 字段名 default 默认值;
③Mysql(版本8.0.25)中表student_table(id,name,birth,sex),插入如下记录:
('1004' , '张三' ,'2000-08-06' , '男');
('1009' , '李四', '2000-01-01', '男');
('1010' , '李四', '2001-01-01', '男');
('1006' , '王五', '2000-08-06' , '女');
('1008' , '张三', '2002-12-01', '女');
('1012' , '张三', '2001-12-01', '女');
('1011' , '李四', '2002-08-06' , '女');
执行
select t1.*,t2.*
from (
select * from student_table where sex = '男' ) t1
full outer join
(select * from student_table where sex = '女')t2
on t1.name = t2.name ;
的结果行数是:会报执行错误。
解析:
Mysql(版本8.0.25)不支持full join,执行报错【1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'full outer join 】
④某打车公司要将驾驶里程(drivedistanced)超过5000里的司机信息转存到一张称为seniordrivers 的表中,他们的详细情况被记录在表drivers 中,正确的sql语句为()
解析:
INSERT INTO table_name VALUES (值1, 值2,....) 指定所要插入数据的列: INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
把所有的列插入新表 SELECT * INTO new_table_name [IN externaldatabase] FROM old_tablename
只把希望的列插入新表 SELECT column_name(s) INTO new_table_name [IN externaldatabase] FROM old_tablename
⑤SQL语句中,可以查看到学生信息表中,学生姓名的SQL语句为:
select * from 学生信息 或者 select 学生姓名 from 学生信息