1.where 字段名 regexp '正则表达式'

正则符号: ^ $ . [ ] * |
. 表示1个任意字符
* 表示前面重复0次,或者任意次
^ 开始
$ 结尾
[] 范围
| 或                         

sql示例:

#查询以【李】开头的
select name from user where name regexp '^李';
#查询以【小】结尾的
select name from user where name regexp '小$';
#查询以【李】开头,中间任意,结尾以【四】的
select name from user where name regexp '^李.*四$';
#查询名字以【李】开头,或者以【小】结尾的
select name from user where name regexp '^李|小$';

2. instr、concat搜索和连接字符串

数据字段中存放的是id集,形如  1,2,15,35 也可类推json格式
查询时不用拆分了, 用上 instr、concat搜索和连接字符串
查询ids中包含15的

sql示例:

select * from [table-表名] where instr(concat(',', ids, ','), ',15,') > 0

3.查询时,多个字段 like 同个值

like多个值 and和的关系
like多个值 or的关系 可用regexp

sql示例:

select * from user where name regexp '张三|李四'

4.查询结果过滤

having用法:
SQL查询 having 条件表达式;就是在查询结果中再查询一次

sql示例:

select name from user where name !="李四" having name="李小小";

5.mysql内置对数据进行统计的指令

聚焦函数:
avg(字段名)
sum(字段名)
min(字段名)
max(字段名)
count(字段名)

sql示例:

##查询名字不等于李四的人员的平均分数
select avg(score) from user where name != "李四";
##查询最高分数
select max(score) from user;
##查询最低分数
select min(score) from user;
##查询总分数
select sum(score) from user;
##统计user表中的行数
select count(*) from user;

6.mybatis中mapper.xml where下foreach写法

A写法:

<where>
ID in
<foreach close=")" collection="array" item="ids" open="(" separator=",">
'${ids}'
</foreach>
</where>

B写法:

<where>
<if test="ids!= null and ids.size() > 0">
and id in
<foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>​
<where>

最新文章

  1. js只允许输入数字
  2. Android源代码结构分析
  3. mysql 模块使用
  4. JVM-class文件完全解析-类索引,父类索引和索引集合
  5. oracle 绑定变量
  6. 开发日志_Jan.9
  7. 【LeetCode】Path Sum 2 --java 二叉数 深度遍历,保存路径
  8. mycat 概述
  9. [HAOI2006]受欢迎的牛
  10. JAVA中事物以及连接池
  11. 重定向URL
  12. Hibernate学习---单表查询
  13. javax.el.PropertyNotFoundException:Property &#39;statisDate&#39; not found on type java.lang.String
  14. workbench的schema讲解一:(维度dimension设置的基本内容)
  15. 一个简单的ruby生成器例子(用连续体Continuation实现)
  16. ajax异步请求302分析
  17. ios-Nav右上角按钮
  18. SpringCloud系列------Eureka-Server
  19. React-state props与render()的关系
  20. IT公司管理发展经验

热门文章

  1. 【SpringBoot】(1)-- 基于eclipse配置springboot开发环境
  2. Go语言核心36讲(Go语言实战与应用十五)--学习笔记
  3. WC 2007 剪刀石头布
  4. 题解 P5320 - [BJOI2019]勘破神机(推式子+第一类斯特林数)
  5. 浏览器点击URL的响应过程
  6. 如何利用官方SDK文件来辅助开发
  7. Echart显示后端mysql数据
  8. 【分布式】Zookeeper伪集群安装部署
  9. ORACLE 服务器验证
  10. [学习总结]1、View的scrollTo 和 scrollBy 方法使用说明和区别