Dit problem er mangel på parenteser:I SQL AND
har forrang over OR
, så du skal sætte parenteser omkring hele dit tidligere udtryk:
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
Uden parenteserne får du A or B or (C and D)
, men du vil have (A or B or C) and D