sql带条件查找最小缺失编号

来源:互联网 发布:校花级别的多漂亮知乎 编辑:程序博客网 时间:2024/06/08 13:13
  查找在CASE_SET_ID为某个条件下的最小缺失编号 如 1 3 获取的值是2 , 2 3则获取的值是1
/**     * select     * case when not exists(select * from rt_test_case where CASE_NUM=1) then 1     * else (select min(IFNULL(CASE_NUM,0)+1)  from rt_test_case  as a     * where     * not exists(     * select CASE_NUM     * from rt_test_case as b     * where IFNULL(a.CASE_NUM,0)+1=b.CASE_NUM AND a.CASE_SET_ID = b.CASE_SET_ID     * ) and CASE_SET_ID = '10383') end     * */