day01/sql/日考一.sql

56 lines
1.8 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 依据上图字段类型一致创建数据库添加至少5条数据。
CREATE TABLE `emp` (
`e_id` int NOT NULL AUTO_INCREMENT,
`e_name` varchar(255) DEFAULT NULL,
`sex` varchar(255) DEFAULT NULL,
`tel` varchar(255) DEFAULT NULL,
`class_id` int DEFAULT NULL,
`age` int DEFAULT NULL,
`sal` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`e_id`)
)
INSERT INTO `test_6_1`.`emp` (`e_name`, `sex`, `tel`, `class_id`, `age`, `sal`) VALUES ('张依依', '', '123456789', 10, 20, 1000.00);
INSERT INTO `test_6_1`.`emp` (`e_name`, `sex`, `tel`, `class_id`, `age`, `sal`) VALUES ('刘晓红', '', '123456781', 20, 20, 1556.00);
INSERT INTO `test_6_1`.`emp` (`e_name`, `sex`, `tel`, `class_id`, `age`, `sal`) VALUES ('李四', '', '123456782', 30, 23, 4567.00);
INSERT INTO `test_6_1`.`emp` (`e_name`, `sex`, `tel`, `class_id`, `age`, `sal`) VALUES ('李强', '', '123456783', 20, 20, 5600.00);
INSERT INTO `test_6_1`.`emp` (`e_name`, `sex`, `tel`, `class_id`, `age`, `sal`) VALUES ('王艳', '', '123456784', 20, 24, 6800.00);
-- 查询所有学生信息,并根据年龄进行降序排序
SELECT * FROM emp ORDER BY emp.age DESC
-- 显示姓王的学生的详细信息。
SELECT * FROM emp WHERE emp.e_name LIKE CONCAT('%','','%')
-- 查询工资大于5000的所有男同学的信息
SELECT * FROM emp WHERE emp.sal > 5000 AND emp.sex =''
-- 查询班级编号为20的男同学的电话号码
SELECT * FROM emp WHERE class_id = 20 AND emp.sex =''
-- 查询最低工资。
SELECT MIN(emp.sal) FROM emp
-- 查询班级为30的学生的最小年龄
SELECT MIN(emp.age) FROM emp WHERE emp.class_id = 30
-- 查询女生的最低工资
SELECT MIN(emp.sal) FROM emp WHERE emp.sex = ''
-- 查询女学生中薪资最低的人的全部信息
SELECT * FROM emp WHERE emp.sal = (SELECT MIN(emp.sal) FROM emp WHERE emp.sex = '')