取最小未用的账号

SELECT NVL(Min(t1.Accnum), 0) + 1
  INTO newAccnum
  FROM T1 t1
 WHERE (t1.accnum + 1) NOT IN (SELECT t2.accnum FROM T2 t2)
   AND t1.accnum > 0
   AND EXISTS (SELECT t3.accnum FROM T3 t3 WHERE t3.accnum = 1);

posted @ 2016-05-03 13:52  珠烁晶莹  阅读(149)  评论(0编辑  收藏  举报