Retrieving data from MYSQL based on week number

后端 未结 3 868
迷失自我
迷失自我 2021-01-27 12:59

I am having a table as follows in MYSQL:

proj_id|hoursWorked|Date.  

The date field is of type Date; I want to retrieve all the e

3条回答
  •  迷失自我
    2021-01-27 13:03

    Do not use something like WHERE WEEK(column)=something - this is a performance killer: It will calculate the week number on all rows, even if they don't match. In addition to that it will make it impossible to use an index ont this column.

    Instead calculate an absolute begin and end date or point in time, depending on your data type, then use BETWEEN. This will do no calculations on non-matching rows and allow the use of an index.

    Rule of thumb: If you have the choice between a calculation on a constant and on a field, use the former.

提交回复
热议问题