+ -
当前位置:首页 → 问答吧 → sql调用判断问题

sql调用判断问题

时间:2011-12-21

来源:互联网

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

作者: a7898585   发布时间: 2011-12-21

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

作者: rucypli   发布时间: 2011-12-21

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 比如)

作者: ACMAIN_CHM   发布时间: 2011-12-21

引用 2 楼 acmain_chm 的回复:
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 al……
这段没明白,可以稍微详细的讲解下吗?是数据库还是直接的php里面执行?

作者: a7898585   发布时间: 2011-12-21

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

作者: WWWWA   发布时间: 2011-12-21

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

作者: ACMAIN_CHM   发布时间: 2011-12-21