mysq中的各类查询语句
先附上表数据
student表
mid_stu_course表
course表
1、全部查询
SELECT *
FROM student
2、like模糊查询
SELECT *
FROM student
WHERE `name` LIKE '%o%'
3、or或者查询
SELECT *
FROM student
WHERE idcard=1 OR idcard=3;
4、and并且查询
SELECT *
FROM student
WHERE `name`="TOM" AND age=18;
5、UNION 用于合并两个或多个 SELECT 语句的结果集,并消去表中任何重复行
SELECT student.idcard
FROM student
UNION
SELECT mid_stu_course.course_id
FROM mid_stu_course
6、GROUP BY分组查询(每个地方平均年龄)
SELECT addr,AVG(age)
FROM student
GROUP BY addr
7、GROUP BY分组查询平均分
SELECT idcard,AVG(grade)
FROM mid_stu_course
GROUP BY idcard
先总结这么多给小伙伴们,具体的还有很多查询可以看下菜鸟教程里面讲的也很详细