MySQL - Sort on a calculated value based on two dates
- by Petter Magnusson
I have the following problem that needs to be solved in a MySQL query:
Fields
info - textfield
date1 - a date field
date2 - a date field
offset1 - a text field with a number in the first two positions, example "10-High"
offset2 - a text field with a number in the first two positions, example "10-High"
I need to sort the records by the calculated "sortvalue" based on the current date (today):
If today=date2 then sortvalue=offset1*10+offset2*5+1000
else sortvalue=offset1*10+offset2*5
I have quite good understanding of basic SQL with joins etc, but this I am not even sure if its possible...if it helps I could perhaps live with a single formula giving the same sort of effect as the IFs do....ie. before date1 = low value, after date2 = high value...
Rgds
PM