时间:2021-07-01 10:21:17 帮助过:11人阅读
INSERT INTO `student` VALUES (1, ‘zazr‘, 11); INSERT INTO `student` VALUES (2, ‘jkg‘, 20); INSERT INTO `student` VALUES (4, ‘zazr‘, 11); INSERT INTO `student` VALUES (5, ‘jkg‘, 12); INSERT INTO `student` VALUES (6, ‘lgh‘, 13); INSERT INTO `student` VALUES (7, ‘zazr‘, 11); INSERT INTO `student` VALUES (8, ‘jkg‘, 12); INSERT INTO `student` VALUES (9, ‘lgh‘, 13); INSERT INTO `student` VALUES (10, ‘zazr‘, 11); INSERT INTO `student` VALUES (11, ‘jkg‘, 12); INSERT INTO `student` VALUES (12, ‘lgh‘, 13);
SELECT * FROM student;
SELECT ROUND(AVG(age),0) from student;
ROUND、AVG都是聚合函数,ROUND(小数,2)表示这个小数四舍五入保留2位小数;AVG求平均值
SELECT name FROM student WHERE age>=(SELECT ROUND(AVG(age),0) FROM student);
创建表:
CREATE TABLE NAME(
-> id int(11) NOT NULL AUTO_INCREMENT KEY,
-> name VARCHAR(20));
SQL语句:
INSERT name(name) SELECT name FROM student GROUP BY name;
UPDATE student INNER JOIN name ON name.name=student.name SET student.name=name.id;
此时可以看:id为1对应的是name表中id为3的名字:zazr
INSERT student VALUES(NULL,"10",24);
INSERT student VALUES(NULL,"8",30);
INSERT name VALUES(NULL,"张三");
INSERT name VALUES(NULL,"李四");
SELECT student.id,name.name FROM student INNER JOIN name ON student.name=name.id;
SELECT student.id,name.name FROM student LEFT JOIN name ON student.name=name.id;
SELECT student.id,name.name FROM student RIGHT JOIN name ON student.name=name.id;
mysql子查询与连接查询
标签:style create from 查询 nbsp set using char general