mysql汇总

一、多个模糊条件查询 regexp

1、group_concat 连接 distinct 去重 SEPARATOR ',' 逗号分割

select FIELD_NAME 字段中文名,GROUP_CONCAT(DISTINCT FIELD_CODE SEPARATOR ',') 字段英文名 from da_dp_table_field where FIELD_NAME regexp '用户编码|客户编码' and DEL_FLAG=0 group by FIELD_NAME;

2、if(type='',1,null)

select crt_user,crt_name,count(IF(type ='更新',1, null)) '更新',

count(IF(type ='订阅',1, null)) '订阅',count(IF(type ='上架',1, null)) '上架',

count(IF(type ='注册',1, null)) '注册' from da_assets_operation_log_book where tenant_id in ('') and create_timeBETWEEN '2023-10-08 23:59:59' AND '2023-10-16 23:59:59' group by tenant_id ;

if(条件,满足,不满足)

SELECT

t2.TENANT_ID as tenantId,

t4.TITLE as title,

t6.DATA_CODE as dataCode,

t4.ASSETS_ID as assetsId,

t4.ASSETS_STAGE

from da_assets t2

inner join da_dp_field t1 on t1.ID = t2.TABLE_OID AND t2.DEL_FLAG = '0' AND t1.DEL_FLAG = '0'

inner join (SELECT IF (ISNULL( t1.ASSETS_VERSION_ID ),( SELECT tt.ID FROM da_assets_version tt WHERE t1.ID = tt.ASSETS_ID AND tt.ASSETS_STAGE = '0' ),t1.ASSETS_VERSION_ID) AS "versionId",t1.ID AS "id" FROM da_assets t1 WHERE t1.CLASSES_ID = '7') t3 on t2.ID = t3.id

inner join da_assets_version t4 on t3.versionId = t4.ID

inner join da_dataset t5 on t4.DATASET_ID = t5.ID

inner join da_dp_field_current t6 on t5.DP_VERSION = t6.ID

inner join da_assets t7 on t1.ASSETS_ID = t7.ID

inner join da_dp_table t8 on t8.OID = t7.TABLE_OID GROUP BY t4.ASSETS_ID;

3、 json解析

t5.CONTENT ->> ' . P R I V C O L 0 01 9 ′ j s o n 包着解析 t 3. C O N T E N T − > > ′ .PRIV_COL_0019' json包着解析 t3.CONTENT ->> ' .PRIVCOL0019′json包着解析t3.CONTENT−>>′.indexInfo.code'

4、查询

SELECT t3.*

FROM(SELECT t1.*,

IF (FIND_IN_SET(parent_id, @pids) > 0,@pids := CONCAT(@pids, ',', id),'0') AS ischild

FROM(SELECT t.id,t.parent_id,t.NAME,t.TITLE

FROM da_tag_dim AS t

ORDER BY t.id ASC) t1,

(SELECT @pids := 'zb2023033100113') t2) t3

WHERE ischild != '0';

5、更新json

JSON_SET(t5.content,' . P R I V C O L 0 02 0 ′ , ′ 2022092501 2 ′ ) 多个: a . c o n t e n t = J S O N S E T ( a . c o n t e n t , ′ .PRIV_COL_0020',' 20220925012') 多个:a.content = JSON_SET(a.content,' .PRIVCOL0020′,′20220925012′)多个:a.content=JSONSET(a.content,′.senCode','20211221004',' . u p d a t e C y c l e I d ′ , ′ 2023091800 1 ′ , ′ .updateCycleId','20230918001',' .updateCycleId′,′20230918001′,′.hasDate','08:00','$.maxAccount','1' )

UPDATE da_dataset_table t5 INNER join da_assets_version t4 on t4.DATASET_ID=t5.DATASET_ID INNER join da_assets a on a.ASSETS_VERSION_ID=t4.id SET t5.content = JSON_SET(t5.content,'$.PRIV_COL_0020','

20220925012') WHERE a.id in ('1020005101168750593');

相关推荐
言慢行善7 小时前
sqlserver模糊查询问题
java·数据库·sqlserver
韶博雅7 小时前
emcc24ai
开发语言·数据库·python
有想法的py工程师7 小时前
PostgreSQL 分区表排序优化:Append Sort 优化为 Merge Append
大数据·数据库·postgresql
喵了几个咪7 小时前
如何在 Superset Docker 容器中安装 MySQL 驱动
mysql·docker·容器·superset
迷枫7127 小时前
达梦数据库的体系架构
数据库·oracle·架构
夜晚打字声8 小时前
9(九)Jmeter如何连接数据库
数据库·jmeter·oracle
Chasing__Dreams8 小时前
Mysql--基础知识点--95--为什么避免使用长事务
数据库·mysql
NineData8 小时前
NineData 智能数据管理平台新功能发布|2026 年 3 月
数据库·oracle·架构·dba·ninedata·数据复制·数据迁移工具
小陈工8 小时前
2026年4月7日技术资讯洞察:下一代数据库融合、AI基础设施竞赛与异步编程实战
开发语言·前端·数据库·人工智能·python
❀͜͡傀儡师8 小时前
k8s部署的Nexus 3 数据库损坏恢复指南:从删除损坏数据库到完整数据重建
数据库·kubernetes·nexus3