CREATE TABLE goods(id INT,goods_name VARCHAR(10),price DOUBLE);
INSERT INTO goods (id,goods_name,price) VALUES(1001,'酒',100.12);
INSERT INTO goods (id,goods_name,price) VALUES(11,'手机',3000);
SELECT * FROM goods;
DESC goods;
INSERT INTO employee (id,user_name,birthday,entry_date,job,Salary,resume,image)VALUES(101,'tim','2022-10-11','2022-10-11 10:10:10','看大门',100.123,'大王派我来巡山','asdas'),(101,'tim','2022-10-11','2022-10-11 10:10:10','看大门',100.123,'大王派我来巡山','asdas');
-- 演示update语句
-- 要求:在上面创建的employee表中修改表中的纪录
-- 1。将所有员工薪水修改为5000元。[如果没有带where,会修改所有的记录,因此小心]UPDATE employee SET salary = 5000;UPDATE employee SET salary = 3000WHERE user_name = '韩顺平';
UPDATE employeeSET salary = salary + 1000WHERE user_name = '韩顺平';
UPDATE employeeSET salary = salary + 1000 , job = '出主意'WHERE user_name = '韩顺平';SELECT * FROM employee;
DESC employee;
DELETE FROM employeeWHERE user_name ='tim';SELECT *FROM employee; DESC employee; INSERT INTO employee (id,user_name,birthday,entry_date,job,Salary,resume,image)VALUES(101,'tim','2022-10-11','2022-10-11 10:10:10','看大门',100.123,'大王派我来巡山','asdas'),(101,'tim','2022-10-11','2022-10-11 10:10:10','看大门',100.123,'大王派我来巡山','asdas')
-- 删除表中所有记录,老师提醒,一定要小心
DELETE FROM employee;UPDATE employee SET job = '' WHERE user_name = 'tim' ; DROP TABLE employee;
ALTER TABLE student CHANGE `NAME` `name` VARCHAR(32) NOT NULL DEFAULT ''-- 查询姓名为赵云的学生成绩
SELECT * FROM studentWHERE `name` = '二飞';
-- 查询英语成绩大于90分的同学
SELECT * FROM student WHERE english >= 80;
-- 查询总分大于200分的所有同学
SELECT 'name' AS '名字',(chinese + english + math) AS total_score FROM student;
SELECT * FROM studentWHERE (chinese + english + math)>250;
-- 先改一下值,
UPDATE student-- SET id = 4SET math =100WHERE `name` = '张飞';
-- 查询math大于60并且(and)id大于4的学生成绩
SELECT * FROM studentWHERE math > 60 and id >1 ;
-- 查询英语成绩大于语文成绩的同学
SELECT * FROM studentWHERE english>chinese; -- 查询总分大于200分并且数学成绩小于语文成绩,的姓韩的学生。
SELECT * FROM student WHERE (english + chinese + math)>200 AND math < chinese AND `name` LIKE '李%';
SELECT * FROM student-- WHERE english >=80 AND english <=90; WHERE english BETWEEN 80 AND 90;SELECT * FROM student -- WHERE math = 89 OR math = 90 OR math = 91;WHERE math IN(89,90,91);
SELECT * FROM student WHERE `name` LIKE '李%';SELECT * FROM student WHERE math >80 AND chinese >80;
SELECT * FROM student-- WHERE english >=80 AND english <=90; WHERE english BETWEEN 80 AND 90;SELECT * FROM student -- WHERE math = 89 OR math = 90 OR math = 91;WHERE math IN(89,90,91);
SELECT * FROM student WHERE `name` LIKE '李%';SELECT * FROM student WHERE math >80 AND chinese >80;SELECT * FROM studentWHERE chinese BETWEEN 50 AND 90;SELECT (english + math + chinese) AS '总分' FROM student; SELECT * FROM studentWHERE (english + math + chinese) IN (210,254,257);
-- 查询所有姓李或者姓宋的学生成绩。
SELECT * FROM student WHERE `name` LIKE '李%' OR `name` LIKE '二%';
-- 查询数学比语文多30分的同学
SELECT * FROM studentWHERE (math-chinese) = 1;
-- 演示order by使用
-- 对数学成绩排序后输出【升序】。
SELECT * FROM studentORDER BY math ASC; -- 默认就是升序
SELECT * FROM studentORDER BY math DESC;
-- 对总分按从高到低的顺序输出
-- SELECT * FROM student -- ORDER BY (english + math + chinese) DESC;SELECT `name`,(english + math + chinese) AS total_score FROM studentORDER BY total_score DESC;-- 对姓李的学生成绩排序输出(升序)
SELECT `name`, (english + math + chinese) AS total_score FROM studentWHERE `name` LIKE '李%'ORDER BY total_score;
DESC student;