首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

not exists,该怎么处理

2012-01-19 
not existsselect*fromc1astwherenotexists((selectcount(*)fromc1wheret.score c1.score) 2)为什么出错

not exists
select   *   from   c1   as   t   where   not   exists((
select   count(*)   from   c1   where   t.score> c1.score)   > 2)
为什么出错?能这样使用吗?

[解决办法]
select * from c1 as t where --not exists
((select count(*) from c1 where t.score> c1.score)> 2)
not exists用法不正确
[解决办法]
--try
select * from c1 as t where (select count(*) from c1 where t.score> c1.score)> 2

[解决办法]
不要用not exists
例如:
if exists(select 1 from sysobjects where id=object_id( 'tablename '))
drop table tablename

也可以写成:
if (select count(1) from tablename )> 0
drop table tablename

热点排行