MySQL - Sort on a calculated value based on two dates
Posted
by Petter Magnusson
on Stack Overflow
See other posts from Stack Overflow
or by Petter Magnusson
Published on 2010-05-25T19:47:44Z
Indexed on
2010/05/25
19:51 UTC
Read the original article
Hit count: 307
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
© Stack Overflow or respective owner