Name | Sex | Age | Address |
张三 | 女 | 19 | 北京 |
李四 | 男 | 20 | 上海 |
王五 | 女 | 25 | 广州 |
薛六 | 女 | 20 | 北京 |
王五 | 男 | 22 | 北京 |
赵七 | 男 | 28 | 上海 |
张四 | 女 | 23 | 北京 |
(1). 写出sql语句,查询所有年龄大于20岁的员工
(2). 写出sql语句,查询所有年龄大于等于22小于25的女性员工
(3). 写出sql语句,统计男女员工各有多少名
(4). 写出sql语句,按照年龄降序获取员工信息
(5). 写出sql语句,获取员工中哪个姓名具有重名现象
(6). 写出sql语句,查询所有姓张的员工
(7). 写出sql语句,查询住址为北京的前3条记录
(8). 写出sql语句,查询员工总数
(9). 写出sql语句,向表中插入一条记录
(10).写出sql语句,修改员工张四的住址为南京
(11).写出sql语句,删除年龄大于24岁的女员工
创建数据库的语句:
CREATE DATABASE database_name;
创建员工表的语句:
CREATE TABLE employee (
id INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(50),
Sex VARCHAR(10),
Age INT,
Address VARCHAR(100)
);
进行查找:
(1)SELECT * FROM employee WHERE Age > 20;
(2)SELECT * FROM employee WHERE Age >= 22 AND Age < 25 AND Sex = '女';
(3)SELECT Sex, COUNT(*) FROM employee GROUP BY Sex;
(4)SELECT * FROM employee ORDER BY Age DESC;
(5)SELECT Name FROM employee GROUP BY Name HAVING COUNT(*) > 1;
(6)SELECT * FROM employee WHERE Name LIKE '张%';
(7)SELECT * FROM employee WHERE Address = '北京' LIMIT 3;
(8)SELECT COUNT(*) FROM employee;
(9)INSERT INTO employee (Name, Sex, Age, Address) VALUES ('李五', '男', 30, '上海');
(10)UPDATE employee SET Address = '南京' WHERE Name = '张四';
(11)DELETE FROM employee WHERE Age > 24 AND Sex = '女';