1.insert_select 的使用:从一个表复制数据给另一个表
INSERT INTO students(name,sex,LikeBooksNUM,LikesportNUM,average)
SELECT
name,sex,LikeBooksNUM,LikesportNUM,average
FROM students_copy;2.REGEXP :正则表达式的使用,BINARY 是标明正则的检索区分大小写
SELECT students.`name` FROM students WHERE students.`name` REGEXP BINARY "Jack";
3.聚合函数,COUNT(*),AS 表别名,GROUP BY,WITH ROLLUP
SELECT sex ,COUNT(*) AS Sex_num FROM students GROUP BY sex WITH ROLLUP;
4,左外部联结 LEFT/RIGHT OUTER JOIN 表列名 ON 联结:选择左边/右边所有的行:例如可以检索某些值为NULL的列
SELECT students.`name`,students.sex,COUNT(sorce.average) AS average_num
FROM students LEFT OUTER JOIN sorce ON students.average=sorce.average GROUP BY students.name;5,使用触发器:CREATE TRIGGER(触发器)AFTER INSERT ON students_copy 更新的表 FOR EACH ROW UPDATE 执行更新手段 (students_count SET students_count=students_count+1)
CREATE TRIGGER newname AFTER INSERT ON students_copy FOR EACH ROW
UPDATE students_count SET students_count=students_count+1;6,UPDATE 要操作的表 SET 操作指令 WHERE 查询条件:需要注意的是 列名要避开mysql的关键字,例如:name等;
UPDATE students_copy
SET `students_name`="david" WHERE average=100;7,联结表的操作,使操作变得更简单
SELECT
students.`name`
FROM students,sorce,books
WHERE students.average=sorce.average AND sorce.id=books.id AND books.id=161034168,表的自联结:
SELECT s1.name,s1.average FROM students AS s1,students AS s2 WHERE s1.`name`=s2.`name` AND s1.LikeBooksNUM=3;