当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式

mms89757 mms89757 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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执行结果中的号码

怎么写才对呢
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
mms89757
疑难问题 22,298 成员 121,727 内容