0

这是我的代码:

SELECT t.obsid, t.seq_nbr, t.charge_ao_str
    , t.approved_exposure_time, t.status, t.uninterrupt
    , t.phase_constraint_flag, t.multitelescope
    , t.multitelescope_interval, t.constr_in_remarks
    , t.remarks, t.window_flag, t.roll_flag, t.monitor_flag
    , t.pre_id, t.pre_min_lead, t.pre_max_lead, r.roll_constraint
    , r.roll_180, r.roll, r.roll_tolerance, w.window_constraint
    , w.tstart, w.tstop, p.phase_period, p.phase_epoch
    , p.phase_start, p.phase_end, p.phase_start_margin, p.phase_end_margin 
FROM target t, rollreq r, timereq w, phasereq p 

WHERE t.obsid=r.obsid 
    AND t.obsid=w.obsid 
    AND t.obsid=p.obsid 
    AND t.charge_ao_str='13' 
    AND (t.status <> 'canceled' OR t.status <> 'untriggered') 
    AND 
    (
        (t.uninterrupt='Y' OR t.uninterrupt='P') OR 
        (t.phase_constraint_flag='Y' OR t.phase_constraint_flag='P') OR 
        (t.multitelescope='Y' OR t.multitelescope='P') OR 
        (t.constr_in_remarks='Y' OR t.constr_in_remarks='P') OR 
        (t.window_flag='Y' OR t.window_flag='P') OR 
        (t.roll_flag='Y' OR t.roll_flag='P') OR 
        (t.monitor_flag='Y' OR t.monitor_flag='P')
    )

它似乎只识别语句t.charge_ao_str='13'中的WHERE,而没有别的。我怎样才能使WHERE语句的其余部分起作用?

4

2 回答 2

0

尝试使用JOIN 看看是否有效

SELECT t.obsid, t.seq_nbr, t.charge_ao_str
    , t.approved_exposure_time, t.status, t.uninterrupt
    , t.phase_constraint_flag, t.multitelescope
    , t.multitelescope_interval, t.constr_in_remarks
    , t.remarks, t.window_flag, t.roll_flag, t.monitor_flag
    , t.pre_id, t.pre_min_lead, t.pre_max_lead, r.roll_constraint
    , r.roll_180, r.roll, r.roll_tolerance, w.window_constraint
    , w.tstart, w.tstop, p.phase_period, p.phase_epoch
    , p.phase_start, p.phase_end, p.phase_start_margin, p.phase_end_margin 
FROM target t 
INNER JOIN rollreg r ON t.obsid=r.obsid 
INNER JOIN timereq w ON t.obsid=p.obsid 
INNER JOIN phasereq p ON t.obsid=p.obsid 
WHERE  
    AND t.charge_ao_str='13' 
    AND (t.status <> 'canceled' OR t.status <> 'untriggered') 
    AND 
    (
        (t.uninterrupt='Y' OR t.uninterrupt='P') OR 
        (t.phase_constraint_flag='Y' OR t.phase_constraint_flag='P') OR 
        (t.multitelescope='Y' OR t.multitelescope='P') OR 
        (t.constr_in_remarks='Y' OR t.constr_in_remarks='P') OR 
        (t.window_flag='Y' OR t.window_flag='P') OR 
        (t.roll_flag='Y' OR t.roll_flag='P') OR 
        (t.monitor_flag='Y' OR t.monitor_flag='P')
    )
于 2012-07-27T14:40:51.900 回答
0

首先,我会考虑使用JOIN语法而不是逗号。请参阅下面的更新查询和JOIN语法。

第二,你确定你有符合所有WHERE条件的记录吗?

SELECT t.obsid, t.seq_nbr, t.charge_ao_str
    , t.approved_exposure_time, t.status, t.uninterrupt
    , t.phase_constraint_flag, t.multitelescope
    , t.multitelescope_interval, t.constr_in_remarks
    , t.remarks, t.window_flag, t.roll_flag, t.monitor_flag
    , t.pre_id, t.pre_min_lead, t.pre_max_lead, r.roll_constraint
    , r.roll_180, r.roll, r.roll_tolerance, w.window_constraint
    , w.tstart, w.tstop, p.phase_period, p.phase_epoch
    , p.phase_start, p.phase_end, p.phase_start_margin, p.phase_end_margin 
FROM target t
INNER JOIN rollreq r
    ON t.obsid=r.obsid 
INNER JOIN timereq w
    ON t.obsid=w.obsid 
INNER JOIN phasereq p 
    ON t.obsid=p.obsid 
WHERE t.charge_ao_str='13' 
    AND t.status NOT IN ('canceled', 'untriggered') 
    AND 
    (
        t.uninterrupt IN ('Y', 'P') OR 
        t.phase_constraint_flag IN ('Y','P') OR 
        t.multitelescope IN ('Y','P') OR 
        t.constr_in_remarks IN ('Y', 'P') OR 
        t.window_flag IN ('Y', 'P') OR 
        t.roll_flag IN ('Y', 'P') OR 
        t.monitor_flag IN ('Y', 'P')
    )
于 2012-07-27T14:38:58.780 回答