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
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.