mysql数据库查询练习答案

更新时间:2024-04-24 17:24:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1. 已知:员工信息表,表名为:employee Name 张三 李四 王五 薛六 王五 赵七 张四 Sex 女 男 女 女 男 男 女 Age 19 20 25 20 22 28 23 Address 北京 上海 广州 北京 北京 上海 北京 (1). 写出sql语句,查询所有年龄大于20岁的员工(2分) Select * from employee where age > 20

(2). 写出sql语句,查询所有年龄小于25岁的女性员工(3分) Select * from employee where age < 25 and sex = ‘女’

(3). 写出sql语句,统计男女员工各有多少名(3分) Select count(name),sex, from employee group by sex

(4). 写出sql语句,按照年龄倒序获取员工信息(3分) Select * from employee order by age desc

(5). 写出sql语句,获取员工中哪个姓名具有重名现象(3分) Select name from employee group by name having count(name) > 1

(6). 写出sql语句,查询所有姓张的员工(3分) Select * from employee where name like ‘张%’

(7). 写出sql语句,查询住址为北京的前3条记录(3分) --Select top 3 * from employee where address = ‘北京’ Select * from employee where address = ‘北京’ limit 0,3

(8). 写出sql语句,查询员工总数(3分) Select count(*) from employee

(9). 写出sql语句,向表中插入一条记录(2分)

Insert into employee (Name, Sex, Age, Address) values (‘名字’, ‘女’, 12, ‘地址’);

(10).写出sql语句,修改员工张四的住址为南京(2分) Update employee set address = ‘南京’ where name = ‘张四’

(11).写出sql语句,删除年龄大于24岁的女员工(2分) Delete from employee where age > 24 and sex = ‘女’

本文来源:https://www.bwwdw.com/article/1wpp.html

Top