mysql中函数find_in_set可以对字符串在某个字段中是否存在,如果存在则返回含有该查询项的所有记录
SELECT
count(1)
FROM
contingency_plan_team_role
WHERE
find_in_set( 36, preview_task_ids)>0;
如果=0,则表示不存在
查询结果:
第二种情况数据库字段有可能是json类型字段,则此时需要使用JSON_EXTRACT函数进行查询
demo sql:
SELECT
*
FROM
contingency_plan_release_history
WHERE
plan_id = 100
AND JSON_EXTRACT( plan_base_json, '$.processTime' ) = 1676596298000
完美查出结果来。
case when 进行分组判断
case when release_time IS NOT NULL and `status`=0 then 4
when release_time IS NOT NULL and `status`=2 then 5
when release_time IS NOT NULL and `status`=3 then 6
else `status`
end as STATUS
case when的语法规则为
case when 条件 then 结果
when 条件 then 结果
when 条件 then 结果
else 结果
end as 别名