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\[ \< ]>

<

相关推荐
L1624762 小时前
MySQL 全环境生产快速安装 + 完整配置手册(整合国产银河麒麟适配 + 主从补充版)
数据库·mysql
yio_yin2 小时前
Spring事务管理(数据一致性)
数据库·sql·spring
前端双越老师2 小时前
如何以前端视角(非0基础)学 Java ?
java·node.js·全栈
前端世界2 小时前
MySQL 基础入门(学习第4天)——约束与 DML 操作详解
数据库·学习·mysql
dear_bi_MyOnly2 小时前
【SpringBoot配置文件】
java·spring boot·后端·学习·spring·java-ee·学习方法
做个文艺程序员3 小时前
Linux第22篇:用Docker容器化你的Java SaaS应用:一次构建,随处运行
java·docker·容器
其美杰布-富贵-李4 小时前
Spring Boot 依赖注入说明文档
java·spring boot·python
tachibana24 小时前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
our_times4 小时前
2026年Java开发者破局指南:Spring AI 2.0 与 Agent 开发实战
java·人工智能·spring
Csvn4 小时前
📊 SQL 入门 Day 9:CTE(公用表表达式)— 让 SQL 像写代码一样优雅
后端·sql