1:查询条件为某字段中字符串第几位是什么
//field 字段字符串中从第一位起数两位为01的 exp:010025 | 015263 | 019988 select * from table where substring(field,1,2)='01'
2:查所有包含标签为 “tp” 的文章,数据库文章标签字段为 tag 格式为 a,b,c,d
① sql 原生查询 select * from table where ( FIND_IN_SET( $tp , tag )) ②tp5 框架条件查询 Db::table('table')->where('find_in_set('.$tp.',tag)')->select(); //或者map集合 map可加入其他条件 exp: $map['del'] = 0; $map[] = ['exp',Db::raw('FIND_IN_SET('.$tp.',tag)')];
3:TP按照日期-》两小时内、当日、本周、本月、本年的数据
// 获两小时内数据 Db::table('table')->whereTime('times','-2 hours')->select(); // 获取当日的数据 whereTime('times', 'd') Db::table('table') ->whereTime('times', 'today
SQL查询条件笔记
最新推荐文章于 2022-04-07 16:41:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)