select a.STCD,a.TM,a.Z,a.Q,a.XSA,a.XSAVV,a.XSMXV,a.FLWCHRCD,a.WPTN,a.MSQMT,a.MSAMT,a.MSVMT, b.STNM,b.RVNM,b.STLC,b.BGFRYM,c.LDKEL,c.RDKEL,c.WRZ,c.GRZ,c.OBHTZ,c.OBHTZTM,(a.Z-c.WRZ) OWRZ,(a.Z-c.GRZ) OGRZ,(a.Z-c.OBHTZ) OHTZ
from ST_RIVER_R a,ST_STBPRP_B b,ST_RVFCCH_B c
where a.STCD=b.STCD and a.STCD=c.STCD and a.TM between '2009-09-13 13:00:00' and '2009-09-14 13:00:00' and (a.STCD = '30301400' or a.STCD = '30301600' or a.STCD = '30301800' or a.STCD = '30301801' or a.STCD = '30301804') and -5.0<=OWRZ and OWRZ<0 order by a.STCD asc
根据错误提示“OWRZ是无效的列名”,你看一下a.Z和c.WRZ这两列的字段类型是否匹配。
楼上分析的没错;
你检查下这两相字段是否一致?从最后的where条件来看,都是double 或float?
另外,你可以把语句多写出几行,以便系统提示第几行出错
试下这个
select a.STCD,a.TM,a.Z,a.Q,a.XSA,a.XSAVV,a.XSMXV,a.FLWCHRCD,a.WPTN,a.MSQMT,a.MSAMT,a.MSVMT,
b.STNM,b.RVNM,b.STLC,b.BGFRYM,c.LDKEL,c.RDKEL,c.WRZ,c.GRZ,c.OBHTZ,
c.OBHTZTM,(a.Z-c.WRZ) OWRZ,(a.Z-c.GRZ) OGRZ,(a.Z-c.OBHTZ) OHTZ
from ST_RIVER_R a,ST_STBPRP_B b,ST_RVFCCH_B c
where a.STCD=b.STCD and a.STCD=c.STCD and a.TM between '2009-09-13 13:00:00' and '2009-09-14 13:00:00'
and (a.STCD = '30301400' or a.STCD = '30301600' or a.STCD = '30301800' or a.STCD = '30301801' or a.STCD = '30301804')
and OWRZ>=-5 and OWRZ<0 order by a.STCD asc
MSSQL中只能如此,否则也报错"列名 '***' 无效。"
select * from
(
select a.STCD,a.TM,a.Z,a.Q,a.XSA,a.XSAVV,a.XSMXV,a.FLWCHRCD,a.WPTN,a.MSQMT,a.MSAMT,a.MSVMT, b.STNM,b.RVNM,b.STLC,b.BGFRYM,c.LDKEL,c.RDKEL,c.WRZ,c.GRZ,c.OBHTZ,c.OBHTZTM,(a.Z-c.WRZ) OWRZ,(a.Z-c.GRZ) OGRZ,(a.Z-c.OBHTZ) OHTZ
from ST_RIVER_R a,ST_STBPRP_B b,ST_RVFCCH_B c
where a.STCD=b.STCD and a.STCD=c.STCD and a.TM between '2009-09-13 13:00:00' and '2009-09-14 13:00:00' and (a.STCD = '30301400' or a.STCD = '30301600' or a.STCD = '30301800' or a.STCD = '30301801' or a.STCD = '30301804') order by a.STCD asc
)
where -5.0<=OWRZ and OWRZ<0
可能还是你原来的语句放在where内层效率高。但是你的or条件似乎可以用in更好些。
你试着跟踪一下语句看看