mysql的常用函数

1、保留两位小数

Round(rent_income/10000,2) rent_income,

2、where 条件

where m1.is_deleted = 0

-- 物料编号/名称/入库单号/入库仓库

and (

m3.material_no like CONCAT('%','1','%')

or m3.material_name like CONCAT('%','1','%')

or m1.stock_in_single_no like CONCAT('%','1','%')

or m4.warehouse_name like CONCAT('%','1','%')

)

and m1.project_id in ( 322,323 )

and m1.audit_status = 1003

and date_format(m1.stock_in_time, '%Y-%m-%d') > '2022-04-29'

and date_format(m1.stock_in_time, '%Y-%m-%d') < '2022-08-29'

3、日期相减

DATEDIFF(cont_real_end_date,cont_begin_date)

4、最大值

select max(submit_time) from asset_operating_fixed

where is_deleted = 0 and project_id = pm.id

and date_format( submit_time, '%Y-%m' ) <= date_format( NOW(), '%Y-%m' )

5、if语句

IF(mom.month_profit = NULL,NULL,(hb.month_profit - mom.month_profit)/mom.month_profit) as month_profit_mom,

GROUP BY m1.id

6、指定数据库

-- and table_schema = 'amp_xinjin'

7、查询表的所有字段名称 各种拼接

-- column_comment COLUMN_NAME

-- "id":"自增id",

-- select GROUP_CONCAT('"' ,COLUMN_NAME ,'":"',column_comment,'"') from information_schema.COLUMNS

-- where table_name = 'project_format_records' ;

-- "id","project_id",

-- select GROUP_CONCAT('"',COLUMN_NAME,'"' ) result from information_schema.COLUMNS

-- where table_name = 'project_format_records' ;

-- id,project_id,

select GROUP_CONCAT('' ,COLUMN_NAME ,'') from information_schema.COLUMNS

where table_name = 'project_format_records' ;

8、xml里面的小于号
<!CDATA\[ \< ]>

<

相关推荐
Decay__1 小时前
PostgreSQL DBA 日常运维手册 —— 会话、锁阻塞、慢查询、膨胀与每日巡检
运维·数据库·sql·postgresql
FungLeo2 小时前
FengCMS ·PHP+MySQL 升级实录· 设置发布与模板缓存:数据库与配置文件如何避免旧表单覆盖
数据库·mysql·php·工程实践·fengcms
会编程的吕洞宾3 小时前
Spring AI 2.0 工具调用实战:让 AI 自动调用你的 Java 方法
java·人工智能·经验分享·后端·spring
斯维赤3 小时前
SELECT * 为什么是覆盖索引的天敌?
java·后端·mysql
FungLeo3 小时前
FengCMS · PHP+MySQL 升级实录· 编译缓存并发:锁定产物执行、避免重复发布与三类缓存清理
mysql·缓存·php·并发·fengcms
kiwixing3 小时前
GaussDB|几台机器、哪种协议:高可用部署形态与副本协议选型
数据库·sql·database·gaussdb
stormsha3 小时前
库存 5,10 个并发各买 1 件:为什么最后不剩 -5 件
java·数据库·mysql
SongRenShuo4 小时前
三年 MyBatis 排查史:从我翻日志,到让 SQL 自己浮现
sql·mybatis·idea·日志·调试
RobinXYuan4 小时前
【Java 字节码探秘】02 ClassFile 骨架:十个字段
java·jvm·源码阅读
炸薯条!4 小时前
Python面向对象基础:类与对象、实例方法、魔法方法和属性详解
java·开发语言·python