查询
select student.* from student
select student.name studnetName from student where id=#{id}
此处studnetName为别名
条件查询运算符
除了=还有许多符号可以使用
- 等于(=)
- 不等于(<>、!=) # 两者意义相同,在可移植性上前者优于后者
- 大于(>) # 字符按照 ASCII 码对应的值进⾏⽐较,⽐较时按照字符对应的位置⼀个字符⼀个字符的⽐较。
- 小于(<)
- 小于等于(<=)
- 大于等于(>=)
逻辑查询运算符
- AND(并且)
- OR(或者)
- like(模糊查询)
- BETWEEN … AND(区间查询)
- IN 查询
- not in
- IS NULL
- IS NOT NULL
- limit ⽤来限制 select 查询返回的⾏数,常⽤于分页等操作
一对多查询
把多条信息整合成一条信息
select name,group_concat(distinct dic_test.name) AS categoryName from student group by test.name
group_concat(distinct dic_test.name) AS categoryName
+
group by test.name
=
在一对多查出多条信息的情况下,通过上述代码可以实现两条信息合并成一条
添加
insert into student(name,sex,age) values(#{name},#{sex},#{age})
修改
update student set name=#{name},sex=#{sex} where id = #{id}
删除
delete from student where id = #{id}