WHERE 条件の順序を変更すると、異なる結果が得られますが、その理由がわかりません。
SELECT
...
WHERE (
-- Ramps that start this month
(r.start_dte > ? AND r.start_dte <= ?)
OR
-- Ramps that end this month and have no follow-up.
(r.end_dte >= ? AND r.end_dte <= ? AND r.id = m.latestId)
)
-- Throw out expired schedules or contracts
AND (s.term_dte > r.start_dte or s.term_dte is null)
AND (c.term_dte > r.start_dte or c.term_dte is null)
-- Throw out a ramp if its end date is before its start date
AND (r.end_dte > r.start_dte)
AND s.name not like '%zz%'
私の意図は、最初の 2 つの条件のうちの 1 つが満たされ (ランプは今月開始するか、今月終了してフォローアップがない必要があります)、他のすべての条件が満たされることです。私はこれを書いていませんか?
最後から 2 番目の条件に違反する結果が得られているため、正しく機能していないことはわかっていAND
ます。