当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式
if exists(select * from sysobjects where name='Result' )
drop table Result
select LineNum as 线路,SIM as 号码 into Result from UV_MsgInbox t1
where t1.MsgArrivedTime >= dateadd(minute,-5,getdate())
and MsgTitle='外接电源断电,启动内置电源'
and not exists(select * from UV_MsgInbox t2
where t2.Sender = t1.SIM
and t2.MsgArrivedTime >= dateadd(minute,-5,getdate())
and t2.MsgTitle ='恢复正常供电')
group by t1.SIM,t1.LineNum
select 线路 from Result group by 线路 having count(DISTINCT 号码)>=2
if exists(select 线路 from Result group by 线路 having count(DISTINCT 号码)>=2)
begin
declare @receiver varchar(500)
set @receiver='13737740287,15878359061,15812405921'
if exists (select * from UV_MsgInbox t1 where t1.MsgType=1 and t1.MsgArrivedTime >= dateadd(minute,-5,getdate())
and t1.sender in (select 号码 from Result group by 号码 having count(DISTINCT 号码)>=2))--后半括号中子查询不对
子查询想要的是select 线路,号码 from Result group by 线路,号码 having count(DISTINCT 号码)>=2这条sql执行结果中的号码
怎么写才对呢
...全文
相关推荐
SQL-Server2000-错误-1--999-说明.doc
#### 11615 当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式**描述**: 如果子查询没有通过 `EXISTS` 引入,则在 `SELECT` 列表中只能有一个表达式。
MySQL的子查询中FROM和EXISTS子句的使用教程
有时候,JOIN或条件表达式可能提供更好的性能。因此,在编写查询时,应该根据实际情况测试和优化。
sql中exists的用法
需要注意的是,exists 和 in 操作符的使用场景类似,但它们的语法和执行机制不同。in 操作符用于检测一个值是否在一个列表中,而 exists 用于检测子查询是否返回至少一个记录。
sql exists和not exists用法
#### EXISTS 介绍`EXISTS`关键字用于检查子查询是否至少返回一行数据。如果子查询返回至少一行数据,则`EXISTS`表达式返回`TRUE`;如果没有数据返回,则返回`FALSE`。
SQL子查询和嵌套查询
- **使用IN关键字**:将一个表达式的值与子查询生成的一组值进行匹配。- **使用NOT IN关键字**:将一个表达式的值与子查询生成的一组值进行不匹配的比较。


疑难问题
