josn字段中不存在数据或者不存在某个key进行sql查询时报错问题解决

2022-03-24 12:21:16 浏览数 (1)

代码语言:javascript复制
//获取面试结果为已通过的
Integer passInterviewList = baseMapper.selectCount(new QueryWrapper<NeoCrmCustomerInterview>()
        .and(ele -> ele.eq("interview_status_init", CustomerInterviewEnum.PASS_WAIT_FEEDBACK.getCode()).or()
                .eq("interview_status_init", CustomerInterviewEnum.PASS_FEEDBACK.getCode()))
        //优化sql,interviewer_json未null或key不存在指定数据时会报错--优化兼容不存在问题
        //.last("and interviewer_json -> '$.interviewerId' like '%"   id   "%'"));
        .last("CASE WHEN JSON_VALID(interviewer_json) THEN JSON_UNQUOTE(JSON_EXTRACT(interviewer_json, '$.interviewerId')) like '%"   id   "%' ELSE null END"));

0 人点赞