select*from t_student where student_name like'王_'-- 查询姓为‘王’开头,并且名字仅为2位的所有信息,_代表任一字符select*from t_student where student_name like'王%'-- 查询姓为‘王’开头的所有信息,%代表任意多个字符select*from t_student where student_name like'%天%'-- 查询所有姓名中包含‘天’的信息-- 这里主要理解 % 和 _ 的作用,如有不明,可以去搜索一下
In 条件查询
select*from t_student where student_no in(1001,1002,1003)-- 查询学号为1001,1002,1003的信息-- in 同时可以和 % 和 _ 结合使用
Join On 联结查询
自连接
select a.`menu_name`as'父菜单', b.`menu_name`as'子菜单'from t_menu as a, t_menu as b where a.id = b.parent_id
-- 如果理解不了上面这句话,可以设计一个包含 id,name,parentid 三列的表,来对照一下,其中parentid一定是id的子集
-- 子查询的本质是 嵌套 查询,例如select*from t_student
where student_id in(select student_id from result where score >=80)-- 多重子查询(嵌套)select*from t_studen
where student_id in(select student_id from result
where score >=80and subject_id in(select subject_id from subject where subject_name ='高等数学-1'))