Home > Software design >  Optimal way for selecting all possible 6 month intervals using values 1 through 12
Optimal way for selecting all possible 6 month intervals using values 1 through 12

Time:12-21

I have been able to select every possible six month interval using a month_num column. I am wondering if there is a more performant way to do this?

What I have tried (which does do what I want):

SELECT * FROM date_table

WHERE month_num in (1, 7)   OR
                month_num in (2, 8)   OR
                month_num in (3, 9)   OR
                month_num in (4, 10)  OR
                month_num in (5, 11)  OR
                month_num in (6, 12)

Is there a better way?

Thanks!

CodePudding user response:

Based on your statement that the original query returns what you want, you can rewrite it in a more efficient fashion as so:

  SELECT *
    FROM data_table
   WHERE month_num >= 1 and month_num <= 12;
  • Related