模糊查询、limit、count、distinct

如果查询条件中的字段中包含%或者下划线,那么模糊匹配怎么写?
select * from 表名 where 字段 like ‘%%%’ ESCAPE ‘’;
在like后面的模糊搜索字串中的百分号%之前使用转义字符,比如\,再用escape指定该转义字符,例如like ‘abc%ef’ escape ‘’;

1、limit——sql语句
Limit[初始位置],记录数 >默认为0
select * from employee order by salary limit5,5; >取5~10号

2、count语句
count:统计非空的个数 >count(*),建议使用count (1)
count(1) 会统计表中的所有的记录数,包含字段为null 的记录

3、过滤重复数据
DISTINCT:过滤重复数据
select distinct 字段名 from 表名;

猜你喜欢

转载自blog.csdn.net/weixin_43750327/article/details/84798121