- update:使用非索引字段time查询报错
解决方案:加上limit的限制,以免全表操作
例:update tableName set rt_no =‘123456’ where update_time between ‘2023-06-30 00:00:00’ and ‘2023-07-01 00:00:00’ limit 10; - concat:数据库查询字段连接显示 如:<分类代码 分类名称> tagName
例:select category_code,category_name,concat(category_code,’ ',category_name) tagName from mrs_category where category_code in(64,641,6412,64122) and business_type=1 ;
- date_sub:日期减多少天,解放双手哈哈,业务场景中很多这种处理日期的。【日期加多少天用date_add】
例:select schedule_start_time,date_sub(schedule_start_time,INTERVAL 5 DAY) start_date ,date_sub(schedule_start_time,INTERVAL 1 DAY) end_date from wms_stockin_schedule ;
 days from wms_stockin_schedule ;
因为开始日期<结束日期,然后计算出来的天数差是有正负的,如果不看重这个含义的话,可以取绝对值ABS()。
例: select schedule_start_time,schedule_end_time,ABS(datediff(schedule_start_time,schedule_end_time)) days from wms_stockin_schedule;
- substr:字符串的截取,比如时间我只想要年月日
例:select substr(now(),1,10) ‘today’,
substr(date_add(substr(now(),1,10),INTERVAL 1 DAY),6,10) ‘1day’ ,
substr(date_add(substr(now(),1,10),INTERVAL 2 DAY),6,10) ‘2days’,
substr(date_add(substr(now(),1,10),INTERVAL 3 DAY),6,10) ‘3days’ from dual;
6.CEILING(float),数值向上取整
CEILING(SUM(wsg.real_op_num
) /(wsg.om/wsg.op)) realBox ; 例如:CEILING(3.2); 返回 4