1

下面是我的 SQL 查询的一部分。我想从显示的时间段中选择数据。我有许多特定的日期范围需要包含在“或”语句中。如何更改我的查询以使其按预期工作。

          where and a1.TS between (('01-MAR-18 06:40:00.0' and '02-MAR-18 06:40:00.0') or ('04-MAR-18 06:40:00.0' and '05-MAR-18 06:40:00.0'))
                and a1.name =  'WV3_NDC_Avg123_Moistur'                                                    
                and a2.name =  'WV3_SAWDI_NO'
                and a3.name =  'WV3_PRODUCT'
                and a4.name =  'WV3_CI_FO_NO_CHUTES'
                and a5.name =  'WV3_VS_DFWL_COL_B'
                and a6.name =  'WV3_FOM_ONSTS'
                and a8.name =  'WV3_OVM_ONSTS'
                and a9.name =  'WV3_PI_OV_RAMP_HGHT_SF'
                and a10.name = 'WV3_PULLCAM_TOT_MINMONTH'
                and a11.name = 'WV3_VS_BAT_HGT_AVG'
                and a12.name = 'WV3_LD_BOVEN_S'
                and a13.name = 'WV2_THEO_LSPD_ADJ'

这个查询是用 Aspen SQLPlus 编写的,并且正在访问一个历史数据库。为了使查询正常工作,我创建了一个临时表,并查询该表。我不知道这是否有所作为,但值得注意。

还,

where a1.TS between '01-MAR-18 06:40:00.0' and '02-MAR-18 06:40:00.0'

工作得很好。

4

1 回答 1

3

您需要重复列名:

where ( (a1.TS between '01-MAR-18 06:40:00.0' and '02-MAR-18 06:40:00.0') or
        (a1.TS between '04-MAR-18 06:40:00.0' and '05-MAR-18 06:40:00.0')
      ) and
      . . .
于 2018-03-07T18:48:06.610 回答