比如一个字段里面储存着数字
现在想做个判断,就是1-20,这样20个数字,如果数据库里有就不显示数字,如果数据库里没有哪个数字就显示出来.请教下这样该怎么写?

解决方案 »

  1.   

    一条sql实现不了 需要写存储过程 或者程序中实现
      

  2.   

    select * from (
    select 1 as id union all
    select 2  union all
    select 3  union all
    select 4  union all
    select 5  union all
    select 6  union all
    select 7  union all
    select 8  union all
    select 9  union all
    select 10  union all
    select 11  union all
    select 12  union all
    select 13  union all
    select 14  union all
    select 15  union all
    select 16  union all
    select 17  union all
    select 18  union all
    select 19  union all
    select 20
    ) t 
    where id not in (select 一个字段 from 比如)
      

  3.   

    这段没明白,可以稍微详细的讲解下吗?是数据库还是直接的php里面执行?
      

  4.   

    就是生成1-20数字,运行UNION ALL看看结果
      

  5.   

    算了,帮你移到PHP版吧。
    SQL语句的基础建议先看一下。