数据库系统原理与应用教程(058)—— MySQL 练习题(二):单选题

1、在成绩表中查询绩点在 3.7-4.0 之间,并且挂科数为 0 的学生的所有信息。下列SQL语句不正确的是(D)。

A、SELECT * FROM 学生 WHERE 绩点>=3.7 and 绩点<=4.0 and 挂科数=0;
B、SELECT * FROM 学生 WHERE 绩点 BETWEEN 3.7 and 4.0 and 挂科数=0;
C、SELECT * FROM 学生 WHERE 绩点>=3.7 and (绩点<=4.0 and 挂科数=0);
D、SELECT * FROM 学生 WHERE 挂科数=0 and (绩点>=3.7 OR 绩点<=4.0);

2、在下列sql语句错误的是?(B)

A、name IS NULL
B、name == NULL
C、name IS NOT NULL
D、NOT(name IS NULL)

3、检索销量表中销量最好的商品 id 和销量(假设每件商品只有一个订单),下列SQL语句正确的是()。

A、SELECT 商品id, 销量 FROM 销量表 WHERE 销量=MAX(销量);
B、SELECT 商品id, MAX(销量) FROM 销量表 GROUP BY 销量;
C、SELECT 商品id, MAX(销量) FROM 销量表 GROUP BY 商品id;
D、SELECT 商品id, 销量 FROM 销量表 WHERE 销量=(SELECT MAX(销量) FROM 销量表);

4、某学院包含多个专业如计算机科学、信息管理、软件工程、网络工程。每个专业每年都招收一个班级的学生。在招生过程中就已明确规定,一个学生只能就读于该学院的一个班级,但是一个班级可以招收不超过 60 个学生。那么,班级和学生之间是(A)的关系。

A、一对多 B、多对多 C、一对一 D、多对一

5、MySQL是一种(C )数据库管理系统。

A、层次型 B、网络型 C、关系型 D、对象型

6、查询运动员表中运动员的所有信息,按照年龄升序,成绩降序排列。下列SQL语句正确的是(C)。

A、SELECT * FROM 运动员 ORDER BY 年龄,成绩;
B、SELECT * FROM 运动员 ORDER BY 1 ASC,2 DESC;
C、SELECT * FROM 运动员 ORDER BY 年龄 ASC,成绩 DESC;
D、SELECT * FROM 运动员 ORDER BY 年龄 DESC,成绩 ASC;

7、SQL中属于分组查询的语句是?()

A、Where              B、Order by            C、Group by             D、Having

8、有一个 User 表,现要删除整张表(指完全删除表数据和表结构),下面正确的MySQL语句是(B)。

A、DELETE TABLE User;                 B、DROP TABLE User
C、TRUNCATE TABLE user;               D、DELETE FROM User ;

9、user 表包含如下信息:

mysql> select * from user;
+------+-------+
| id   | name  |
+------+-------+
|    1 | tom   |
|    2 | jack  |
|    3 | mark  |
|    4 | black |
+------+-------+
4 rows in set (0.04 sec)

把 name 列的所有值都转换为大写,并将字段重命名为 names,如下所示。

+-------------+
| names       |
+-------------+
| TOM         |
| JACK        |
| MARK        |
| BLACK       |
+-------------+
4 rows in set (0.01 sec)

下列语句正确的是(B)。

A、SELECT LCASE(name) AS names FROM user;
B、SELECT UCASE(name) AS names FROM user;
C、SELECT CASE(name) AS names FROM user;
D、SELECT UCASE(name)  FROM user;

10、下列哪个语句是授予用户 SQLTest 对数据库 Sales 的 CUSTOMERS 表的列 cid、cname 的查询权限?(C)

A、grant select on cid,cname to SQLTest;
B、grant select on cid,cname with SQLTest;
C、grant select on Sales.CUSTOMERS(cid,cname) to SQLTest;
D、grant select on Sales.CUSTOMERS(cid,cname) with SQLTest;

11、永久删除 waterinfo001表,选出符合要求的语句。(C)

A、DELETE TABLE waterinfo001;
B、DELETE FROM TABLE waterinfo001;
C、DROP TABLE waterinfo001;
D、DROP FROM TABLE waterinfo001;

12、有三张数据表:学生,课程,选修。

学生(学号,姓名,性别,专业号)
课程(课程号,课程名,学分)
选修(学号,课程号,成绩)

下列选项对于上述模式的参照完整性叙述不正确的是(D)。

A、“选修” 关系中的 “学号” 是一个外键,引用了 “学生” 中的“学号”
B、“选修” 关系中的 “课程号” 是一个外键,引用了 “课程” 中的 “课程号”
C、“学号”、“课程号” 分别为 “学生”、“课程” 关系中的主键
D、“学生” 关系中的属性 “学号” 可以唯一标识一个元组,但不可以唯一标识学生实体

13、下列关于视图说法错误的是?(D)

A、视图是虚表,它在存储时只存储视图的定义,而没有存储对应的数据
B、创建视图用 CREATE VIEW
C、修改视图用 ALTER VIEW
D、删除视图用DELETE VIEW

14、表 student_table(id,name,birth,sex),有如下记录:

('1001' , '' , '2000-01-01' , '男')
('1004' , '张三' , '2000-08-06' , '男')
('1005' , NULL , '2001-12-01' , '女')
('1006' , '张三' , '2001-12-02' , '女')

执行:

select t1.name from (select * from student_table where sex = '女') t1;

结果行数为(C)。

A、4 B、3 C、2 D、1

15、数据库中有 person 表,主键是 id,task 表,主键也是 id,两个表中的数据如下:

mysql> select * from person;
+----+------+
| id | name |
+----+------+
|  1 | tom  |
|  2 | jack |
+----+------+
2 rows in set (0.00 sec)

mysql> select * from task;
+----+-----------+---------------+
| id | person_id | content       |
+----+-----------+---------------+
|  1 |         2 | T1 works well |
|  2 |         2 | T2 works well |
+----+-----------+---------------+
2 rows in set (0.00 sec)

查找每个人的任务情况(没有任务输出 NULL),结果按 id 降序排列,输出结果:

+----+------+---------------+
| id | name | content       |
+----+------+---------------+
|  2 | jack | T1 works well |
|  2 | jack | T2 works well |
|  1 | tom  | NULL          |
+----+------+---------------+
3 rows in set (0.12 sec)

正确的SQL查询语句为(A)。

A、SELECT p.id, p.name, t.content 
   FROM person AS p LEFT JOIN task AS t ON p.id = t.person_id ORDER BY p.id DESC;
B、SELECT p.id, p.name, t.content 
   FROM person AS p JOIN task AS t ON p.id = t.person_id ORDER BY p.id DESC;
C、SELECT p.id, p.name, t.content 
   FROM person AS p RIGHT JOIN task AS t ON p.id = t.person_id ORDER BY p.id DESC;
D、SELECT p.id, p.name, t.content 
   FROM person AS p INNER JOIN task AS t ON p.id = t.person_id ORDER BY p.id DESC;

16、在 gameList 表中 (player_id, event_date) 是主键,如何查找出每个 player_id 的第一次登录的时间(event_date)?(A)

player_id

device_id

event_date

games_played

111

21

2020-03-01

5

111

21

2020-01-02

6

212

33

2020-09-03

1

322

11

2020-01-21

0

322

44

2020-03-02

5

A、SELECT player_id, min(event_date) as first_login  FROM gameList GROUP BY player_id;
B、SELECT player_id, min(device_id) as first_login  FROM gameList GROUP BY player_id;
C、SELECT player_id, event_date as first_login  
   FROM gameList GROUP BY player_id WHERE min(event_date);
D、SELECT player_id, min(event_date) as first_login  
   FROM gameList WHERE min(event_date)  GROUP BY player_id;

17、表 employees 和 dept_nanager,数据如下:

mysql> SELECT * FROM employees;
+--------+---------+------------+---------+
| emp_id | name    | birth_date | country |
+--------+---------+------------+---------+
|   1001 | W ZHANG | 1998-01-02 | CN      |
|   1002 | WBD     | 1996-10-18 | JAP     |
|   1003 | TOM     | 1990-08-08 | USA     |
|   1004 | ROSE    | 1997-12-09 | UK      |
|   1005 | WW LI   | 1994-06-20 | CN      |
+--------+---------+------------+---------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM dept_nanager;
+--------+---------+------------+---------+
| emp_id | name    | birth_date | country |
+--------+---------+------------+---------+
|   1001 | J LI    | 1990-06-15 | CN      |
|   1002 | DW ZHAO | 1992-07-28 | CN      |
|   1003 | BLACK   | 1994-06-15 | USA     |
+--------+---------+------------+---------+
3 rows in set (0.00 sec)

从 employees 表和 dept_manager 表中选取出所有的 county 值(包含重复值)并按 county 的升序排列,结果如下:

+---------+
| country |
+---------+
| CN      |
| CN      |
| CN      |
| CN      |
| JAP     |
| UK      |
| USA     |
| USA     |
+---------+
8 rows in set (0.02 sec)

下面的查询语句正确的是(C)。

A、SELECT country FROM employees UNION SELECT country FROM dept_manager ORDER BY country;
B、SELECT country FROM employees UNION SELECT country FROM dept_manager ORDER BY country DESC;
C、SELECT country FROM employees UNION ALL SELECT country FROM dept_manager ORDER BY country;
D、SELECT country FROM employees UNION ALL SELECT country FROM dept_manager ORDER BY country DESC;

18、下列关于索引的描述不正确的是(C)。

A、可通过索引快速查找数据,减少查询执行时间
B、数据库索引采用 B+ 树是因为 B+ 树在提高了磁盘 IO 性能的同时解决了元素遍历效率低下的问题
C、如果WHERE 子句中使用了索引,则 ORDER BY 子句中不会使用索引
D、索引提高了查询速度,也会提高更新表的速度

19、数据表:student_table(id,name,birth,sex),查询重复姓名、重复次数,并按重复次数降序排列,正确的是(A)?

A、select name, count(\*) as c1 
   from student_table group by name having c1 > 1 order by c1 desc ;
B、select name, count(\*) as c1 
   from student_table group by name having c1 > 1 order by c1;
C、select name, count(\*) as c1 
   from student_table group by name where count(\*)  > 1 order by c1 desc;
D、select name, count(\*) as c1 
   from student_table group by name where c1 > 1order by c1 desc;

20、学生成绩表 score,部分内容如下:

name course grade
张三 操作系统 67
张三 数据结构 86
李四 软件工程 89

用一条 SQL 语句查询出每门课都大于 80 分的学生姓名,正确的 SQL 语句为(A)。

A、Select distinct name from score where name not in(Select name from score where grade <= 80);
B、Select distinct name from score where name  in(Select name from score where grade <= 80);
C、Select  name from score where name not  in(Select name from score where grade <= 80);
D、Select  name from score where name  in(Select name from score where grade <= 80);

21、表:student_table(id,name,birth,sex),中有如下记录:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘张三’ , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘李四’ , ‘2001-12-02’ , ‘女’)

查询男生女生存在的相同姓名,比如’张三’ ,正确的是(A)?

A、select distinct t1.name 
   from(select * from student_table where sex = '女') t1 inner 
   join (select * from student_table where sex = '男') t2 on t1.name = t2.name;
B、select distinct t1.name 
   from (select * from student_table where sex = '女') t1 
   left join (select * from student_table where sex = '男') t2 on t1.name = t2.name;
C、select distinct t1.name 
   from (select * from student_table where sex = '女') t1 
   full join(select * from student_table where sex = '男') t2 on t1.name = t2.name;
D、select distinct t1.name 
   from (select * from student_table where sex = '女') t1 
   right join(select * from student_table where sex = '男') t2 on t1.name = t2.name;

21、表:student_table(id,name,birth,sex) 中的数据如下:

(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , NULL , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘张三’ , ‘2000-08-06’ , ‘女’)
(‘1007’ , ‘王五’ , ‘2001-12-01’ , ‘男’)
(‘1008’ , ‘李四’ , NULL, ‘女’)
(‘1009’ , ‘李四’ , NULL, ‘男’)
(‘1010’ , ‘李四’ , ‘2001-12-01’, ‘女’)

执行:

select count(t2.name) as c1
from (
select * from student_table where sex = '男' ) t1 
left join 
(select * from student_table where sex = '女') t2 
on t1.birth = t2.birth and t1.name = t2.name;

查询结果行数是?(C)

A、3 B、2 C、1 D、4

22、数据库中有作家信息表:author(作者编号aid,作者姓名aname,作者笔名ausername,作者邮箱aemail,备注remarks),稿件表:manuscript(稿件编号mid,标题mtitle,作者编号aid,交稿时间mtime)。

要设置外键作者编号,下列语句正确的是(D)。

A、ALTER TABLE manuscript ADD CONSTRAINT FK_aid FOREIGN KEY (aid) REFERENCE author (aid);
B、ALTER TABLE manuscript ADD CONSTRAINT FK_aid FOREIGN KEY (manuscript.aid) REFERENCE author(aid);
C、ALTER TABLE manuscript ADD FOREIGN KEY (manuscript.aid) REFERENCES author;
D、ALTER TABLE manuscript ADD FOREIGN KEY (aid) REFERENCES author (aid);

23、有数据表:student_table(id,name,birth,sex),查询男生、女生人数分别最多的 3 个姓氏及人数,正确的SQL是(C)。

A、SELECT sex ,substr(name,1,1) as first_name, count(*) as c1 
   from student_table where length(name) >=1 
   group by first_name, sex order by  sex ,c1 desc limit 3;
B、SELECT sex ,substr(name,1,1) as first_name ,count(*) as c1 
   from student_table where length(name) >=1  and sex = '男' 
   group by first_name  order by  sex ,c1 desc limit 3 
   union all 
   SELECT sex ,substr(name,1,1) as first_name ,count(*) as c1 
   from student_table where length(name) >=1  and sex = '女' 
   group by first_name  order by  sex ,c1 desc limit 3;
C、select * from (SELECT sex ,substr(name,1,1) as first_name,count(*) as c1 
   from student_table where length(name) >=1  and sex = '男' 
   group by first_name  order by  sex ,c1 desc limit 3) t1 
   UNION all
   select * from (SELECT sex,substr(name,1,1) as first_name,count(*) as c1 
   from student_table where length(name) >=1 and sex = '女'
   group by first_name order by  sex ,c1 desc limit 3 ) t2;
D、select * from (SELECT sex ,substr(name,1,1) as first_name ,count(*) as c1 
   from student_table where length(name) >=1  and sex = '男' 
   group by first_name  having c1 >=3  order by  sex ,c1 desc ) t1 
   UNION all
   select * from (SELECT sex ,substr(name,1,1) as first_name ,count(*) as c1 
   from student_table where length(name) >=1 and sex = '女'
   group by first_name having c1 >=3  order by  sex ,c1 desc limit 3 ) t2;

24、语句GRANT、REVOKE实现了结构化查询语言的哪类功能?(C)

A、DDL B、DML C、DCL D、数据库事务

25、数据表:student_table(id,name,birth,sex),score_table(stu_id,subject_name,score),查询每个学生的学科总分最高的学生信息以及总分,如下SQL正确的是(A)。

A、select  t2.*,c1 as `最高分` 
   from (select stu_id,sum(score) as c1 from score_table group by stu_id order by c1 desc limit 1) t1 
   join student_table t2 on t1.stu_id = t2.id;
B、select  t2.*,c1 as `最高分` 
   from (select stu_id,max(score) as c1 from score_table group by stu_id order by c1 desc limit 1) t1 
   join student_table t2 on t1.stu_id = t2.id;
C、select  t2.*,c1 as `最高分` 
   from (select stu_id,max(sum(score)) as c1 from score_table group by stu_id 
         order by c1 desc limit 1) t1 
   join student_table t2 on t1.stu_id = t2.id;
D、select  t2.*,c1 as `最高分` 
   from (select stu_id,max(sum(score)) as c1 from score_table group by stu_id) t1 
   join student_table t2 on t1.stu_id = t2.id;

26、下面哪一个是MySQL查询语句的正确执行顺序?(C)

A、SELECT ---> FROM(including JOINs) ---> WHERE ---> GROUP BY ---> HAVING ---> DISTINCT ---> ORDER BY ---> LIMIT/OFFSET
B、SELECT ---> DISTINCT --->  FROM(including JOINs) ---> WHERE ---> GROUP BY ---> HAVING ---> ORDER BY ---> LIMIT/OFFSET
C、FROM(including JOINs) ---> WHERE ---> GROUP BY ---> HAVING ---> SELECT ---> DISTINCT ---> ORDER BY ---> LIMIT/OFFSET
D、FROM(including JOINs) ---> WHERE ---> GROUP BY ---> HAVING ---> DISTINCT --->  SELECT ---> ORDER BY ---> LIMIT/OFFSET

27、数据表:student_info(id,name,birth,sex),字段类型都是 varchar,插入数据:1018 , 赵六 , 2003-08-02 , 男;

正确的 SQL 命令是(C)。

A、insert overwrite student_info values('1018','赵六','2003-08-02','男');
B、insert into student_info values(1018, '赵六','2003-08-02','男');
C、insert into student_info(`birth`,`id`,name,`sex`) values('2003-08-02','1018','赵六','男');
D、insert into student_info value('1018','赵六','2003-08-02','男');

28、数据表:student_table(id,name,birth,sex),数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’)

执行如下命令:

执行:

select t1.name, t2.name from  (select * from student_table where sex = '女') t1 
left join (select * from student_table where sex = '男') t2
on t1.name=t2.name where t2.name is null
union
select t1.name ,t2.name from 
(select * from student_table where sex = '女') t1 
right join (select * from student_table where sex = '男') t2
on t1.name=t2.name where t2.name is null;

查询结果的记录行数为(C)。

A、1 B、2 C、3 D、4

29、从学生信息表(student)中提取姓名(name)列值为NULL的记录,下列选项正确的是(D)。

A、SELECT * FROM student WHERE name IS NOT NULL;
B、SELECT name FROM student WHERE IS NULL;
C、SELECT name FROM student WHERE it IS NULL;
D、SELECT * FROM student WHERE name IS NULL;

30、已知数据表 STU,创建视图 view_s 显示所有男同学的信息。下列 SQL 语句正确的是(B)。

A、CREATE VIEW AS SELECT * FROM STU;
B、CREATE VIEW view_s AS SELECT * FROM STU WHERE 性别='男';
C、CREATE  view_s  SELECT * FROM STU WHERE 性别='男';
D、CREATE  view_s AS SELECT * FROM STU;

31、创建新用户 nkw,对于任何 IP 都可以连接,拥有 user 数据库中所有表的 select 和 insert 权限,能够实现这一要求的语句是(B)。

A、grant select,insert on *.* to 'nkw'@'%';
B、grant select,insert on user.* to 'nkw'@'%';
C、grant all privileges on *.* to 'nkw'@'%';
D、grant all privileges on user.* to 'nkw'@'%';

32、要查询选修了 3 门以上课程的学生的学号,正确的 SQL 语句是(B)。

A、SELECT Sno FROM SC GROUP BY Sno WHERE COUNT(*)> 3;
B、SELECT Sno FROM SC GROUP BY Sno HAVING COUNT(*)> 3;
C、SELECT Sno FROM SC ORDER BY Sno WHERE COUNT(*)> 3;
D、SELECT Sno FROM SC ORDER BY Sno HAVING COUNT(*)> 3;

33、已知职员表:employee(eno,ename,gender,birthday,salary),现有一张 E 表,表结构与职员表一致,要求将 E 表中没有在职员表中出现的女职员添加到职员表中。下列SQL语句正确的是(D)。

A、INSERT INTO employee(eno,ename,gender,birthday,salary)
   SELECT eno,ename,gender,birthday,salsry FROM E WHERE E.gender='女';
B、INSERT INTO employee(eno,ename,gender,birthday,salary)
   SELECT eno,ename,gender,birthday,salsry FROM EWHERE E.gender='女' and 
   EXISTS (SELECT * FROM employee WHERE employee.eno=E.eno);
C、INSERT INTO employee(eno,ename,gender,birthday,salary)
   SELECT eno,ename,gender,birthday,salsry FROM E WHERE E.gender='女' and 
   NOT IN employee;
D、INSERT INTO employee(eno,ename,gender,birthday,salary)
   SELECT eno,ename,gender,birthday,salsry FROM E WHERE E.gender='女' and 
   NOT EXISTS (SELECT * FROM employee WHERE employee.eno=E.eno);

34、数据库中包含如下的数据表:

学生表:student(sno,sname,birthday,gender)
课程表:course(cid,cname)
成绩表:grade(sno,cid,mark)

查询至少有一门课程与 sno=1909 的学生选择的课程相同的学生的学号和姓名,正确的 SQL 语句是(B)。

A、SELECT DISTINCT a.sno,a.sname FROM student a,grade b 
   WHERE a.sno=1909 and a.sno=b.sno and b.cid IN (SELECT cid FROM grade WHERE sno=1909);
B、SELECT DISTINCT a.sno,a.sname FROM student a,grade b 
   WHERE a.sno<>1909 and a.sno=b.sno and b.cid IN (SELECT cid FROM grade WHERE sno=1909);
C、SELECT DISTINCT a.sno,a.sname FROM student a,grade b 
   WHERE a.sno<>1909 and a.sno=b.sno and b.cid NOT IN (SELECT cid FROM grade WHERE sno=1909);
D、SELECT DISTINCT a.sno,a.sname FROM student a,grade b 
   WHERE a.sno=1909 and a.sno=b.sno and b.cid IN (SELECT cid FROM grade WHERE sno<>1909);

35、数据库中保存以下三个表,表结构如下:

运动员:sporter(运动员编号 sporterid,姓名name,性别 sex,所属系号 department)
项目:item(项目编号 itemid,名称 itemname,比赛地点 location)
成绩:grade(运动员编号 id,项目编号 itemid,积分 mark)

用SQL语句完成在“体育馆”进行比赛的各项目名称及其冠军的姓名,正确的 SQL 语句是(A)。

A、SELECT i.itemname, s.name 
   FROM grade g, (SELECT itemid iid,MAX(mark) max FROM grade 
   WHERE itemid IN (SELECT itemid FROM item  WHERE location='体育馆') 
   GROUP BY itemid) temp,
   item i,sporter s WHERE g.itemid=temp.iid AND g.mark=temp.max AND 
   temp.iid=i.itemid AND s.sporterid=g.sporterid;
B、SELECT i.itemname,s.name 
   FROM grade g, (SELECT itemid iid,MIN(mark) max FROM grade 
   WHERE itemid IN (SELECT itemid FROM item WHERE location='体育馆') 
   GROUP BY itemid) temp,
   item i,sporter s WHERE g.itemid=temp.iid AND g.mark=temp.max AND 
   temp.iid=i.itemid AND s.sporterid=g.sporterid;
C、SELECT i.itemname,s.name 
   FROM grade g, (SELECT itemid iid,MAX(mark) max FROM grade 
                  WHERE itemid IN (SELECT itemid FROM item  WHERE location='体育馆')) temp,
   item i,sporter s WHERE g.itemid=temp.iid AND g.mark=temp.max AND 
   temp.iid=i.itemid AND s.sporterid=g.sporterid;
D、SELECT i.itemname,s.name 
   FROM grade g, (SELECT itemid iid,MIN(mark) max FROM grade WHERE itemid 
                  IN (SELECT itemid FROM item  WHERE location='体育馆') GROUP BY itemid) temp,
   item i,sporter s WHERE g.itemid=temp.iid AND g.mark=temp.max;

36、快件信息表:waybillinfo(id, waybillno, zonecode, optype, update_time) 中存储了快件的所有操作信息,请找出在 ‘中山公园’ 网点,异常派送(optype= ‘异常派件’)次数超过 3 次的快件(waybillno),正确的 SQL 语句为(D)。

A、select waybillno, count(*) from waybillinfo 
   where zonecode= '中山公园' and optype= '异常派件' and count(waybillno) >3;
B、select waybillno, count(*) from waybillinfo 
   where zonecode= '中山公园' and optype= '异常派件' order by waybillno having count(*) > 3;
C、select waybillno, count(*) from waybillinfo 
   where zonecode= '中山公园' and optype= '异常派件' having count(*) > 3;
D、select waybillno from waybillinfo 
   where zonecode= '中山公园' and optype= '异常派件' group by waybillno having count(*) > 3;

37、select 语句完整语法如下:

(1)select  目标表的列名或列表达式序列
(2)from 基本表名和(或)视图序列
(3)[where 行条件表达式]
(4)[group by 列名序列 [having 组条件表达式]]
(5)[order by 列名 [asc | desc]]

SQL 语句的执行顺序是(B)。

A、(1),(3),(4),(2),(5) B、(2),(3),(4),(1),(5)
C、(2),(4),(3),(1),(5) D、(2),(3),(5),(1),(4)

38、比赛结果 result 表内容如下:

Date                     Win
2017-07-12               胜
2017-07-12               负
2017-07-15               胜
2017-07-15               负

如果要生成下列结果, 正确的 SQL 语句是(D)。

比赛日期            胜     负
2017-07-12          1      1
2017-07-15          1      1
A、select Date As 比赛日期, (case when Win='胜' then 1 else 0 end) 胜, 
   (case when Win='负' then 1 else 0 end) 负 from result group by Date;
B、select Date As 比赛日期, SUM(case when Win='胜' then 1 else 0 end) 胜, 
   SUM(case when Win='负' then 1 else 0 end) 负 from result;
C、select Date As 比赛日期, SUM( when Win='胜' then 1 else 0 end) 胜, 
   SUM( when Win='负' then 1 else 0 end) 负 from result group by Date;
D、select Date As 比赛日期, SUM(case when Win='胜' then 1 else 0 end) 胜, 
   SUM(case when Win='负' then 1 else 0 end) 负 from result group by Date;

39、在 gameList 表中(player_id, event_date)是主键,如何显示每个玩家(player_id)首次登录的设备号(device_id),并同时显示玩家 ID(player_id)?(D)

player_id

device_id

event_date

games_played

111

21

2020-03-01

5

111

21

2020-01-02

6

212

33

2020-09-03

1

322

11

2020-01-21

0

322

44

2020-03-02

5

A、SELECT player_id, device_id FROM gamelist 
   WHERE event_date IN (SELECT event_date FROM gamelist);
B、SELECT player_id, device_id min(device_id) as first_login 
   FROM gamelist GROUP BY player_id;
C、SELECT player_id, device_id FROM gamelist 
   WHERE event_date IN(SELECT event_date FROM gamelist GROUP BY player_id);
D、SELECT player_id, device_id 
   FROM (SELECT *,rank() over(partition by player_id 
         order by event_date) as rank_date from gamelist) t 
   WHERE t.rank_date=1;

40、将学生信息表的班级列默认值设为 “暂未输入”,下列语句正确的是(C)。

A、ALTER TABLE student MODIFY class CHAR(10) VALUES ('暂未输入');
B、INSERT INTO student (class) VALUES ('暂未输入');
C、ALTER TABLE student MODIFY class CHAR(10) DEFAULT '暂未输入';
D、INSERT INTO student class CHAR(10) DEFAULT '暂未输入';

41、子查询中,父查询中一般使用 IN 运算符的是(B)。

A、单列单值嵌套查询 B、单列多值嵌套查询
C、多列多值嵌套查询 C、集合查询

42、数据表:student_table(id,name,birth,sex),数据如下:

(‘1003’ , NULL , ‘2002-05-20’ , ‘男’)
(‘1004’ ,‘张三’ , ‘2000-09-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)
(‘1006’ , NULL , ‘2001-12-02’ , ‘女’)

修改 name 字段为 NULL 的记录,是男生时设置 name=‘男生姓名’,是女生时设置 name=‘女生姓名’,如下SQL正确的是(D)。

A、update student_table set name = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名' end) if name is null ;
B、update student_table when name is null set name  = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名');
C、update student_table set name = 
   (when sex = '男' then '男生姓名' when sex = '女' then '女生姓名') where name is null;
D、update student_table set name = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名' end) where name is null;

43、数据表:student_table(id,name,birth,sex),score_table(stu_id,subject_name,score),查询没有英语分数的学生信息,正确的 SQL 语句是(B)。

A、select * from student_table  
   where id  in (select stu_id from score_table where subject_name <> '英语');
B、select * from student_table  
   where id not in (select stu_id from score_table where subject_name = '英语');
C、select * from student_table  
   where id not in (select stu_id from score_table where subject_name <> '英语');
D、select * from student_table 
   where id  in (select stu_id from score_table where subject_name = '英语');

44、积分表:result 中有 A、B、C、D 四列,要求:

(1)当 A 列值大于等于 B 列时,选择 A 列,否则选择 B 列。
(2)当 C 列值大于等于 D 列时,选择 C 列否则选择 D 列。

用 SQL 语句实现正确的是(C)。

A、select (when A >=B then A else B) MAX_AB, (when C>=D then C else D) MAX_CD 
   from result;
B、select (case when A>=B then A else B) MAX_AB, (case when C>=D then C else D) MAX_CD 
   from result;
C、select (case when A>=B then A else B end) MAX_AB, (case when C>=D then C else D end) MAX_CD 
   from result;
D、select case when A>=B then A else B end MAX_AB, case when C>=D then C else D end MAX_CD 
   from result;

45、通过子查询的方式从衬衫表 SHIRTABLE 中选取出销售单价 shirt_price 高于全部衬衫的平均价格的衬衫名字,正确的 SQL 语句为(B)。

A、SELECT shirt_id,shirt_name,shirt_price 
   FROM SHIRTABLE WHERE shirt_price > AVG(shirt_price;
B、SELECT shirt_id,shirt_name,shirt_price 
   FROM SHIRTABLE WHERE shirt_price > (SELECT AVG(shirt_price) FROM SHIRTABLE);
C、SELECT shirt_id,shirt_name,shirt_price 
   FROM SHIRTABLE HAVING shirt_price > AVG(shirt_price);
D、SELECT shirt_id,shirt_name,shirt_price 
   FROM SHIRTABLE WHERE shirt_price > 
   (SELECT AVG(shirt_price) FROM SHIRTABLE WHERE shirt_price > AVG(shirt_price));

46、数据表:student_table(id,name,birth,sex),查询不重复的姓名总数,错误的 SQL 语句是(C)。

A、select count(distinct name) from student_table;
B、select count(name) from (select distinct name from student_table ) t1;
C、select count(name) from 
   (select name,count(*) as c1 from student_tablegroup by name having c1 > 1) t1;
D、select count(name) from (select name from student_table group by name) t1;

47、数据表: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’ , ‘女’)

执行如下 SQL 语句:

select t1.*,t2.*
from (
select * from student_table where sex = '男' ) t1 
left join 
(select * from student_table where sex = '女') t2 
on  t1.name = t2.name;

的结果行数是(A)。

A、4 B、3 C、2 D、5

48、下列函数语句得不到相同数值结果的选项是(C)。

A、SELECT ROUND(2.35);
B、SELECT ROUND(1.96,1);
C、SELECT TRUNCATE(1.99,1);
D、SELECT TRUNCATE(2.83,0);

49、确保事务可以多次从一个字段中读取相同的值,在此事务持续期间,禁止其他事务对此字段的更新。
以上是对下列选项哪一个事务隔离级别的描述?(C)

A、Read uncommitted
B、Read committed
C、Repeatable Read
D、Serializable

50、下列关于视图的相关概念描述不正确的是(B)。

A、视图可以解决检索数据时一个表中得不到一个实体所有信息的问题
B、视图是一种数据库对象,是从数据库的表或其他视图中导出的基表
C、若基表的数据发生变化,则变化也会自动反映到视图中
D、数据库存储的是视图的定义,不存放视图对应的数据

51、表结构如下:

CREATE TABLE `score` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `sno` int(11) NOT NULL,
   `cno` tinyint(4) NOT NULL,
   `score` tinyint(4) DEFAULT NULL,
   PRIMARY KEY (`id`)
 ) ;

以下查询语句结果一定相等的是(C)。

(1)SELECT sum(score) / count(*) FROM score WHERE cno = 2;
(2)SELECT sum(score) / count(id) FROM score WHERE cno = 2;
(3)SELECT sum(score) / count(sno) FROM score WHERE cno = 2;
(4)SELECT sum(score) / count(score) FROM score WHERE cno = 2;
(5)SELECT sum(score) / count(1) FROM score WHERE cno = 2;
(6)SELECT avg(score) FROM score WHERE cno = 2;

A、(4),(5),(6)
B、(1),(4),(6)
C、(1),(2),(3),(5)
D、(1),(2),(3),(5),(6)

注意:第(4)中的 count(score) 函数和第6中的 avg(score) 函数统计时忽略空值。

52、在SQL中用条件表示价格在在 30 至 40 之间,应该如何表达?(B)

A、in (30,40)
B、BETWEEN 30 AND 40
C、BETWEEN 30 OR 40
D、BETWEEN 30 TO 40

53、在 book 表中,将工具书类型(tool)的书的书架序号都减少 2,下列语句正确的是(C)。

A、UPDATE books SET shelf = shelf - 2 WHERE type IS 'tool';
B、INSERT books SET shelf = shelf - 2 WHERE type IS 'tool';
C、UPDATE books SET shelf = shelf - 2 WHERE type = 'tool';
D、UPDATE books INTO shelf = shelf - 2 WHERE type = 'tool';

54、当 WHERE子句、GROUP BY子句、HAVING子句、ORDER BY 子句同时出现在一个 SQL 查询语块中时,最后执行的是(D)。

A、WHERE子句
B、GROUP BY子句
C、HAVING 子句
D、ORDER BY子句

55、在 STUDENT 表中按 class_type 统计数据行数分组情况后,筛选出数据行数为大于10行的组。()

SELECT class_type,COUNT(*) FROM STUDENT GROUP BY class_type HAVING COUNT(*)>10;
SELECT class_type,COUNT(*) FROM STUDENT GROUP BY class_type WHERE COUNT(*)=10;
SELECT class_type,COUNT(*) FROM STUDENT HAVING COUNT(*)>10 GROUP BY class_type;
SELECT class_type,COUNT(*) FROM STUDENT WHERE COUNT(*) >10 GROUP BY class_type;

56、下列说法错误的是(C)。

A、模糊查询中,* 表示全部信息
B、可以用统计函数 avg() 计算平均值
C、在使用 insert 语句插入数据时,表达式的数据类型和表格中对应各列的数据类型不一定需要一致
D、视图是数据库对象,可以使用SELECT等语句

57、将成绩表(grade)按成绩(point)升序排列,下列语句错误的是(D)。

A、SELECT * FROM grade ORDER BY point;
B、SELECT point FROM grade ORDER BY point;
C、SELECT * FROM grade ORDER BY point ASC;
D、SELECT * FROM grade ORDER BY point DESC;

58、SQL 中对于数据定义语言 DDL 描述正确的是(D)。

A、DDL 关心的是数据库中的数据
B、数据模型
C、控制对数据库的访问
D、定义数据库的结构

59、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1003’ ,‘男生姓名’ , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘女生姓名’ , ‘2001-12-02’ , ‘女’)

删除符合如下条件的记录:是男生时删除 name=‘男生姓名’ 的记录,是女生时删除 name=‘女生姓名’ 的记录,如下 SQL 正确的是(B)。

A、delete from table student_table where name = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名' end);
B、delete from student_table where name = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名' end);
C、delete from student_table where name = 
   (case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名');
D、delete from student_table where name = 
   (case sex = '男' then '男生姓名' case sex = '女' then '女生姓名' end);

60、请取出 BORROW表中日期(RDATE字段)为当天的所有记录?(RDATE字段为datetime型,包含日期与时间)。正确的 SQL 语句是(A)。

A、select * from BORROW where datediff(RDATE,now())=0;
B、select * from BORROW where RDATE=now();
C、select * from BORROW where RDATE-now()=0;
D、select * from BORROW where RDATE > now();

61、在 SQL 中如何删除触发器?(A)

A、DROP TRIGGER
B、DISABLE TRIGGER
C、REMOVE TRIGGER
D、DELETE TRIGGER

62、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)

查询 2001 年及之后出生的男生、女生总数,正确的 SQL 语句是(C)。

A、select sex,count(*) from student_table group by sex  where birth >='2001';
B、select count(*) from student_table where birth >='2001' group by sex;
C、select sex,count(*) from student_table where birth >='2001' group by sex;
D、select sex,count(*) from student_table group by sex having birth >='2001';

63、现有作家信息表:author(作者编号aid,作者姓名aname,作者笔名ausername,作者地址aaddress,作者邮箱aemail),则插入记录的语句正确的是(C)。

A、INSERT INTO author (aid,aname,ausername,aaddress,aemail)
   VALUES('D770','张三','西泽梦路','123456@126.com');
B、INSERT INTO author VALUES ('D770','张三','西泽梦路','123456@126.com');
C、INSERT INTO author (aid,aname,ausername,aemail)
   VALUES ('D770','张三','西泽梦路','123456@126.com');
D、INSERT INTO author(aname,ausername,aid,aemail)
   VALUES ('D770','张三','西泽梦路','123456@126.com');

64、现有评分表:evaluate(班级编号 cid,分数 point),班级表:grade(班级编号 cid,…)。

查询 evaluate 表中有没有班级均分大于等于 80 分的,如果存在,则查询显示 grade 表按 cid 由大到小排名的前五行记录,下列语句正确的是(B)。

A、SELECT * FROM grade WHERE EXISTS 
   (SELECT cid, AVG(point) AS avg FROM evaluate GROUP BY cid HAVING avg>=80)
   ORDER BY grade.cid;
B、SELECT * FROM grade WHERE EXISTS 
   (SELECT cid, AVG(point) AS avg FROM evaluate GROUP BY cid HAVING avg>=80)
   ORDER BY grade.cid DESC LIMIT 5;
C、SELECT * FROM grade WHERE 
   EXISTS (SELECT AVG(point) AS avg FROM evaluate GROUP BY cid HAVING avg>=80)
   ORDER BY grade.cid DESC LIMIT 5;
D、SELECT * FROM grade WHERE 
   EXISTS (SELECT cid, AVG(point) AS avg FROM evaluate WHERE avg>=80)
   ORDER BY grade.cid DESC LIMIT 5;

65、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , NULL , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’)

执行如下命令:

select t2.name from 
 (select * from student_table where sex = '女') t1 
 right join 
 (select * from student_table where sex = '男') t2 
 on t1.name = t2.name;

该查询的运算结果行数是(A)。

A、4 B、3 C、2 D、1

66、关于视图的描述正确的是(A)。

A、视图可以被嵌套,一个视图中可以嵌套另一个视图
B、视图可以包含 ORDER BY 子句
C、视图可以对临时表或表变量进行引用
D、当底层表数据发生变化时,可使用 SQL 系统存储过程 sp_helptext 更新视图数据

67、已知 student 表(学号sid,姓名sname,考号s_test_id),room 表(考场号rid,座位号rseat,考号s_test_id),下列语句错误的是(D)。

A、CREATE VIEW view_room (sname,s_test_id,rid,rseat) AS
   SELECT student.sname, student.s_test_id, room.rid, room.rseat
   FROM student,room WHERE student.s_test_id=room.s_test_id;
B、CREATE ALGORITHM={TEMPTABLE} VIEW view_room AS
   SELECT student.sname, student.s_test_id, room.rid, room.rseat
   FROM student,room WHERE student.s_test_id=room.s_test_id;
C、CREATE VIEW view_room AS
   SELECT student.sname, student.s_test_id, room.rid, room.rseat
   FROM student,room WHERE student.s_test_id=room.s_test_id;
D、CREATE VIEW view_room AS (rid,rseat,sname,s_test_id)
   SELECT student.sname, student.s_test_id, room.rid, room.rseat
   FROM student,room WHERE student.s_test_id=room.s_test_id;

68、数据表:student_table(id,name,birth,sex),score_table(stu_id,subject_name,score),查询每个学生的分数最高的学科以及对应分数、学生信息,正确的 SQL 语句是(D)。

A、select t3.*,t2.subject_name,t2.score
   from (select stu_id,max(score) as c1 from score_table group by stu_id order by c1 desc limit 1
   ) t1 
   inner join 
   (select * from score_table) t2 on t1.stu_id = t2.stu_id and t1.c1 = t2.score 
   inner join student_table t3 
   on t1.stu_id = t3.id;
B、select t3.*,t2.subject_name,t2.score
   from (select stu_id,max(score) as c1 from score_table group by stu_id) t1 
   inner join 
   (select * from score_table)t2 on t1.stu_id = t2.stu_id 
   inner join student_table t3 
   on t1.stu_id = t3.id;
C、select t3.*,t2.subject_name,t2.score
   from (select stu_id,max(score) as c1 from score_table group by stu_id) t1 
   inner join 
   (select * from score_table)t2 on t1.c1 = t2.score 
   inner join student_table t3 
   on t1.stu_id = t3.id;
D、select t3.*,t2.subject_name,t2.score
   from (select stu_id,max(score) as c1 from score_table group by stu_id) t1 
   inner join 
   (select * from score_table) t2 on t1.stu_id = t2.stu_id and t1.c1 = t2.score 
   inner join student_table t3 
   on t1.stu_id = t3.id;

69、数据表:student_table(id,name,birth,sex),数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , NULL , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’)

执行如下命令:

select t1.name 
 from (select * from student_table where sex = '女') t1 
       inner join 
       (select * from student_table where sex = '男')t2 
       on t1.name = t2.name;

查询结果的行数是(D)。

A、4 B、3 C、2 D、1

70、有 set_teacher表(教师编号s_tid,教师姓名tname,所属院系tdepartment),view_teacher表(教师编号v_tid,教师姓名tname,所属院系tdepartment),question表(题目编号qid,题目类型qtype,题目内容qcontent,答案qanswer,出题教师编号s_tid,审题教师编号v_tid)。

创建一个视图,要求可以查询每题对应出题老师及审题老师,下列语句错误的是(B) 。

A、CREATE VIEW  view_question (qid,s_tname,r_tname)
   AS SELECT question.qid, set_teacher.tname, view_teacher.tname
   FROM question, set_teacher, view_teacher
   WHERE question.s_tid=set_teacher.s_tid
         AND question.v_tid=view_teacher.v_tid;
B、CREATE VIEW  view_question (qid,s_tname,r_tname)
   AS SELECT question.qid, set_teacher.tname, view_teacher.tname
   FROM question, set_teacher, view_teacher
   WHERE (SELECT qid,s_tid,v_tid FROM question
          WHERE question.s_tid=set_teacher.s_tid
          AND question.v_tid=view_teacher.v_tid);
C、CREATE VIEW  view_question (qcontent,s_tname,r_tname)
   AS SELECT question.qcontent, set_teacher.tname, view_teacher.tname
   FROM question, set_teacher, view_teacher
   WHERE question.s_tid=set_teacher.s_tid
         AND question.v_tid=view_teacher.v_tid;
D、SELECT question.qid, set_teacher.tname, view_teacher.tname,
   set_teacher.s_tid, view_teacher.v_tid
   FROM question, set_teacher, view_teacher AS question_2
   WHERE question.s_tid=set_teacher.s_tid
         AND question.v_tid=view_teacher.v_tid;
   CREATE VIEW  view_question (qid,s_tname,r_tname)
   AS SELECT question.qid, set_teacher.tname, view_teacher.tname
   FROM question_2;

71、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)

执行如下命令:

select * from student_table  where name <> '张三';

查询结果的行数是(B)。

A、1 B、2 C、3 D、4

72、不属于数据操纵语言(DML)的选项是(B)。

A、update
B、grant
D、delete
D、insert

73、SQL 查询中 WHere 子句指定(D)。

A、查询目标
B、查询结果
C、查询视图
D、查询条件

73、有下面的数据表:

图书(总编号 char(6), 分类号 char(8), 书名 char(16), 作者 char(6), 出版单位 char(20), 单价 decimal(6,2))
读者(借书证号 char(4),单位 char(8),姓名 char(6),性别 char(2),职称 char(6),地址 char(20))
借阅(借书证号 char(4),总编号 char(6),借书日期 datetime(8))

使用以上数据表查询 0001 号借书证的读者姓名和所借图书的书名。正确的 SQL 语句是(B)。

SELECT 姓名,书名 FROM 借阅,图书,读者 WHERE
借阅.借书证号=“0001” AND ————;

A、图书.分类号=借阅.分类号 AND 读者.借书证号=借阅.借书证号;
B、图书.总编号=借阅.总编号 AND 读者.借书证号=借阅.借书证号;
C、读者.总编号=借阅.总编号 AND 读者.借书证号=借阅.借书证号;
D、图书.总编号=借阅.总编号 AND 读者.书名=借阅.书名;

74、数据表:student_info(id,name,birth,sex),字段类型都是varchar,插入如下记录:(‘1014’ , ‘张三’ , ‘2002-01-06’ , ‘男’); 错误的 SQL 语句是(B)。

A、insert into student_info values('1014', '张三', '2002-01-06', '男');
B、insert into table student_info values('1014', '张三', '2002-01-06', '男');
C、insert into student_info(id,name,birth,sex) values('1014', '张三', '2002-01-06', '男');
D、insert into student_info(id,name,sex,birth) values('1014', '张三', '男','2002-01-06');

75、创建完一张数据表后,发现少创建了一列,此时需要修改表结构,应该用哪个语句进行操作?(C)

A、MODIFY TABLE
B、INSERT TABLE 
C、ALTER TABLE
D、UPDATE TABLE

76、以下 SQL 语句完成的是哪个操作?()

SELECT product_name,sale_price
FROM PRODUCT AS P
WHERE EXISTS (SELECT * FROM SHOPPRODUCT AS SP
WHERE SP.shop_id = ‘00C’ AND SP.product_id = P.product_id);

其中 PRODUCT 表示商品表,SHOPPRODUCT 指商店在售商品表,其中 shop_id 字段表示商店 id,product_id 表示产品 id。

A、选出了 '00C' 商店目前在售的商品价格
B、选出了 '00C' 商店有哪些商品
C、选取出了所有商品价格
D、选取出了 PRODUCT 表和 SHOPPRODUCT 中相同商品的价格

77、某公司人事管理系统的后台数据库名为 LF。新来的人事部张经理在访问员工信息表 EMPL 中的工资和奖金字段的时被拒绝,只能查看该表其他字段。作为 LF 的开发者你将如何解决这一问题?(D)

A、废除张经理的数据库用户帐户对表EMPL里的工资列和奖金列的 SELECT 权限
B、添加张经理到 db_datareader 角色
C、添加张经理到 db_accessadmin 角色
D、授予张经理的数据库用户帐户对表 EMPL 里的工资列和奖金列的 SELECT 权限

78、要删除商品表中价格大于 3000 的商品,正确的 SQL 语句是(A)。

A、DELETE FROM 商品 WHERE 价格>3000;
B、DELETE * FROM 商品 WHERE 价格>3000;
C、DELETE FROM 商品;
D、UPDATE 商品 SET * =NULL WHERE 价格>3000;

79、关于 MySQL 索引的描述正确是(C)。

A、创建UNIQUE索引,索引列的值必须唯一,不允许有空值
B、一个表中可以创建多个全文索引
C、为提高效率可建立组合索引,遵循“最左前缀”原则
D、使用非聚集索引需要将物理数据页中的数据按列重新排序

80、关于数据库系统三级模式结构的表述正确的是(B)。

A、内模式是面向数据库用户或应用程序的局部数据视图
B、索引的组织方式是 B+ 树索引,还是 Hash 索引与数据库的内模式有关
C、逻辑模式是数据库在逻辑级上的视图,涉及数据的物理存储细节
D、外模式/模式映像保证了数据库具有较高的物理独立性

81、grade 表数据如下,要求找出分数重复的数据,正确的 SQL 语句是(A)。

sno

mark

1

85

2

95

3

85

4

78

A、SELECT mark FROM (SELECT mark,COUNT(mark) AS num
   FROM grade GROUP BY mark) AS STATISTIC WHERE num>1;
B、SELECT mark,COUNT(mark)>1 FROM grade GROUP BY mark;
C、SELECT mark FROM (SELECT mark,COUNT(mark) AS num
   FROM grade GROUP BY mark) WHERE num>1;
D、SELECT mark FROM grade GROUP BY mark WHERE COUNT(mark)>1;

82、关于维护参照完整性约束的策略,下列选项描述不正确的是(C)。

A、对于任何违反了参照完整性约束的数据更新,系统一概拒绝执行
B、当删除被参照表的一个元组造成了与参照表的不一致,则删除参照表中的所有造成不一致的元组
C、当修改被参照表的一个元组造成了与参照表的不一致,则修改被参照表中的所有造成不一致的元组
D、当删除或修改被参照表的一个元组造成了不一致,则将参照表中的所有造成和不一致的元组的对应属性设置为空值

83、(多项选择题)针对 having 子句的使用,描述正确的是(A、C)。

A、having 子句即可包含聚合函数作用的字段也可包括普通的标量字段
B、使用 having 的同时不能使用 where 子句
C、having 子句必须于 group by 子句同时使用,不能单独使用
D、使用 having 子句的作用是限定分组条件
E、Having 子句和 where 子句是等同的
F、如果 select 语句中没有聚合函数的使用,就不能使用 having 子句

84、检索所有比 “王华” 年龄大的学生姓名、年龄和性别。正确的 SELECT 语句是(A)。

A、SELECT SN,AGE,SEX FROM S WHERE AGE > (SELECT AGE FROM S WHERE SN="王华");
B、SELECT SN,AGE,SEX FROM S WHERE SN = "王华";
C、SELECT SN,AGE,SEX FROM S WHERE AGE > (SELECT AGEWHERE SN="王华");
D、SELECT SN,AGE,SEX FROM S WHERE AGE > 王华.AGE;

85、如果 ORDER BY 子句未指定 ASC 或 DESC,默认使用以下哪个?(B)

A、DESC
B、ASC
C、不存在默认值
D、其它选项都不对

86、下列不属于触发器事件的是(A)。

A、AFTER
B、UPDATE
C、DELETE
D、INSERT

87、有一订单表 orders,要查找 order_num 不为 NULL 的所有数据,正确的 SQL 语句为(C)。

A、SELECT * FROM orders WHERE order_num != NULL;
B、SELECT * FROM orders WHERE order_num <> NULL;
C、SELECT * FROM orders WHERE order_num IS NOT NULL;
D、SELECT * FROM orders WHERE order_num NOT IS NULL;

88、有选课表:course_relation(student_id, course_id),其中:student_id表示学号,course_id表示课程编号,要获取每个学生所选课程的门数信息,正确的 SQL 语句为(D)。

A、select student_id, sum(course_id) from course_relation;
B、select student_id, sum(course_id) from lcourse_relation group by student_id;
C、select student_id, count(course_id) from course_relation;
D、select student_id, count(course_id) from course_relation group by student_id;

89、数据表:Course,包含数据如下:

user_id

course_status

course_date

2

学习 Python

2021-09-30

要把 Course 表中 user_id 为 2 的 course_status 更新为 ‘学习SQL’,course_date 更新为 ‘2021-10-01’。正确的 SQL 语句为(D)。

A、UPDATE Course SET course_status = '学习SQL', course_date = '2021-10-01';
B、UPDATE Course SET course_status = '学习SQL' AND course_date = '2021-10-01' 
   WHERE user_id = 2;
C、UPDATE Course SET course_status = REPLACE(course_status, '学习SQL', '2021-10-01') 
   WHERE user_id = 2;
D、UPDATE Course SET course_status = '学习SQL', course_date = '2021-10-01' WHERE user_id = 2;

90、有一个学生表:student,要回收所有机器的 nkw 用户对学生表 student 所在数据库 user 的 update 和 insert 权限,下面能够实现这一功能的语句为(C)。

A、revoke update,insert on user.* to 'nkw'@'%';
B、revoke update,insert on *.* to 'nkw'@'%';
C、revoke update,insert on user.* from 'nkw'@'%';
D、revoke update,insert on *.* from 'nkw'@'%';

91、下列操作在视图上无法完成的是(C)。

A、视图数据查询
B、更新视图数据
C、在视图中定义新的基本表 
D、在视图中定义新视图

92、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)

执行如下语句:

select * from student_table where length(name) >= 0;

查询结果行数为(C)。

A、1 B、2 C、3 D、4

93、下面修改表结构的语句中,错误的是(D)。

A、ALTER TABLE class MODIFY name VARCHAR(50);
B、ALTER TABLE student ADD grade INT;
C、ALTER TABLE place CHANGE name p_name VARCHAR(20);
D、ALTER TABLE grade ADD average FIRST;

94、数据中表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)

查询 name 除 ‘张三’ 之外的记录,正确的 SQL 语句为(B)。

A、select * from student_table where name <> '张三' ;
B、select * from student_table where name <> '张三'  or name is null;
C、select * from student_table where name <> '张三'  or length(name) >= 0;
D、select * from student_table where name <> '张三'  and length(name) >= 0;

95、数据库备份类型中,仅记录自最近一次完整数据库备份以后发生改变的数据的是(B)。

A、完整数据库备份
B、差异数据库备份
C、事务日志备份
D、文件和文件组备份

96、有一张学生成绩表 sc(sno 学号,course 课程,score 成绩),数据如下:

sno

course

score

1

English

90

1

Math

89

2

Chinese

99


下面哪个语句可以查询出每个学生的英语、数学的成绩(行转列,一个学生输出一行记录,比如输出:1, 89, 90)(D)。

A、select sno,class,score from sc where class in('english','math');
B、select sno,
   if(class='english',score,0),
   if(class='math',score,0)
   from sc where class in('english','math');
C、select sno,
   case when class='english' then score else 0  end,
   case when class='math' then score else 0 end
   from sc where class in('english','math');
D、select sno,
   sum(if(class='english',score,0)) as english,
   sum( if(class='math',score,0) ) as math
   from sc where class in('english','math') group by sno;

97、订单表:orders(用户信息userid,产品信息productid),以下哪个语句能够返回至少被订购过两次的 productid?(D)。

A、select productid from orders where count(productid)>1;
B、select productid from orders where max(productid)>1;
C、select productid from orders where having count(productid)>1 group by productid;
D、select productid from orders group by productid having count(productid)>1;

98、将 employee 的表名更改为 employee_info,正确的 SQL 语句为(A)。

A、ALTER TABLE employee RENAME  employee_info;
B、ALTER TABLE employee MODIFY  employee_info;
C、ALTER TABLE employee ALTER  employee_info;
D、ALTER TABLE employee CHANGE  employee_info;

99、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1001’ , ’ ’ , ‘2000-01-01’ , ‘男’)
(‘1002’ , null , ‘2000-12-21’ , ‘男’)
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’)

执行如下命令:

select count(name) from student_table;

查询结果中的记录数为(C)。

A、5 B、4 C、3 D、2

100、数据表:student_table(id,name,birth,sex),表中数据如下:

(‘1003’ , ‘’ , ‘2000-01-01’ , ‘男’)
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’)
(‘1005’ , NULL , ‘2001-12-01’ , ‘女’)
(‘1006’ , ‘张三’ , ‘2000-08-06’ , ‘女’)
(‘1007’ , ‘王五’ , ‘2001-12-01’ , ‘男’)
(‘1008’ , ‘李四’ , NULL, ‘女’)
(‘1009’ , ‘李四’ , NULL, ‘男’)
(‘1010’ , ‘李四’ , ‘2001-12-01’, ‘女’)

执行如下命令:

select t1.*,t2.*
from (select * from student_table where sex = '男' ) t1 
inner  join 
(select * from student_table where sex = '女') t2 
on t1.birth = t2.birth and t1.name = t2.name;

查询结果中的记录行数为(D)。

A、4 B、3 C、2 D、1

101、数据表:student_table(id,name,birth,sex),name 字段值存在重复,查询 name 重复的记录信息。比如:‘张三’、‘李四’ 各重复2次,则结果是 4 条。错误的 SQL 语句为(C)。

A、select t2.* 
   from (select name,count(*) as c1 from student_table GROUP BY name  having c1 > 1) t1 
   left join student_table t2 on t1.name = t2.name;
B、select t2.* 
   from (select name,count(*) as c1 from student_table GROUP BY name ) t1 
   left join student_table t2 on t1.name = t2.name
   where c1 > 1;
C、select t2.* ,t1.*
   from (select name,count(*) as c1 from student_table GROUP BY name ) t1 
   left join student_table t2 on t1.name = t2.name
   and  c1 > 1;
D、select t2.* 
   from (select * from (select name,count(*) as c1 from student_table GROUP BY name ) t1
         where c1 > 1) t3
   left join student_table t2 on t3.name = t2.name;

102、数据表:student_table(id,name,birth,sex),查询张姓、李姓的学生总人数,错误的 SQL 语句为(C)。

A、select sum(case when name like '张%' then 1 else 0 end) as zhang_first_name,
   sum(case when name like '李%' then 1 else 0 end) as li_first_name 
   from student_table;
B、select count(case when name like '张%' then 2 else null end) as zhang_first_name,
   count(case when name like '李%' then 2 else null end) as li_first_name 
   from student_table;
C、select count(case when name like '张%' then 1 else 0 end) as zhang_first_name,
   count(case when name like '李%' then 2 else 0 end) as li_first_name 
   from student_table;
D、select sum(case when name like '张%' then 1 else null end) as zhang_first_name ,
   sum(case when name like '李%' then 1 else null end) as li_first_name 
   from student_table;

103、有两张数据:

--表A:
Order_id     User_id    Add_time
11701245001 10000    1498882474
11701245002 10001    1498882475
--表B
id     Order_id     goods_id price
1   11701245001    1001     10
2   11701245001    1002     20
3   11701245002    1001     10

查询购买过 goods_id 为 1001 的用户的 user_id,则下面错误的 SQL 语句为(A)。

A、select user_id from A where order_id = (select order_id from B where goods_id = '1001');
B、select a.user_id from A a,B b where a.order_id=b.order_id and b.goods_id='1001';
C、select user_id from A where order_id in (select order_id from B where goods_id = '1001');
D、Select A.user_id from A left join B on A.order_id=B.order_id where B.goods_id='1001';