mysql8之json类型使用

  • 向json类型字段添加数据

json字段为present

    <update id="updateMeetingPresent" parameterType="HashMap">
        UPDATE tb_meeting
        SET present = JSON_ARRAY_APPEND ( IFNULL( present, JSON_ARRAY() ), '$', #{userId} )
        WHERE id = #{meetingId}
        AND NOW() >= DATE_SUB(CONCAT(date," ",`start`), INTERVAL 15 MINUTE)
        AND NOW() &lt; DATE_SUB(CONCAT(date," ",`end`),INTERVAL 15 MINUTE)
        AND JSON_CONTAINS ( IFNULL( members, JSON_ARRAY ( ) ), CAST( #{userId} AS CHAR ) )
        AND NOT JSON_CONTAINS ( IFNULL( present, JSON_ARRAY ( ) ), CAST( #{userId} AS CHAR ) )
    </update>

上一篇:MySql中的IFNULL、NULLIF和ISNULL用法


下一篇:sql 处理结果可能为 null 的情况