日期:2014-05-17  浏览次数:20384 次

看看这个嵌套SQL有问题吗,老是没数据。
select 
(select MDeviceID from S_MZRelation where ZDeviceID=a.DeviceID)
 from dbo.S_CoalQuality a where CaiYangDT='2013-11-19'


说明:
   1.a.Device在S_CoalQuality表有值。
   2.MDeviceID 和 ZDeviceID 在这个表有对应关系。

可是查询出来的值为 null ,本身是有值的,可能是这个语句有问题

------解决方案--------------------
select from dbo.S_CoalQuality a where CaiYangDT='2013-11-19' and exists(select 1 from S_MZRelation where ZDeviceID=a.DeviceID)

------解决方案--------------------
改成这样呢:
select 
(select MDeviceID from S_MZRelation where CaiYangDT='2013-11-19' and ZDeviceID=a.DeviceID)
 from dbo.S_CoalQuality a where CaiYangDT='2013-11-19'

------解决方案--------------------
亲 一楼已给出正确答案咯