Вашият проблем е липсата на скоби:В SQL AND
има предимство пред OR
, така че трябва да поставите скоби около целия си предишен израз:
SELECT * FROM dim_date
WHERE ( -- added bracket
EXTRACT (MONTH FROM date_cal) BETWEEN 3 AND 5
OR (EXTRACT (MONTH FROM date_cal) = 2 AND EXTRACT (DAY FROM date_cal) >= 15)
OR (EXTRACT (MONTH FROM date_cal) = 6 AND EXTRACT (DAY FROM date_cal) <= 21)
) -- added bracket
AND EXTRACT (YEAR FROM date_cal) BETWEEN 2010 AND 2012
Без скобите получавате A or B or (C and D)
, но искате (A or B or C) and D