I have a MySQL table with the following fields:
id, morning, evening, event, other-fields
For about one week, each day some event will occur either in morning or in evening. Thus the events are recorded in the table with the “day-number” stored in “morning” or “evening” field(if the event is to occur in morning, then morning field contains the “day-number” and evening field contains 0. and vise-versa). These entries are not made sequence-wise or day wise but as per the user’s own will.
I need to fetch these records in proper order i.e. Sort the records day-wise in ascending order and records of each day need to be sorted session-wise(i.e. morning first and then evening ones).
Please help with an idea to order the data on these two fields.
Following is some sample data for three days:
id, mor, even, otherstuff....
1 1 0
2 3 0
3 3 0
4 2 0
5 3 0
6 3 0
--------------------------
7 0 1
8 0 2
9 0 3
10 0 3
----------------------
Following is the same above data in the format I need to fetch it:
id, mor, even, otherstuff....
1 1 0
2 0 1
--------------------------
3 2 0
4 0 2
------------------------
5 3 0
6 3 0
7 3 0
8 3 0
9 0 3
10 0 3
If one of them is always zero, the day number will be equal to
mor + evenso you can sort by that.Since
even = 0for “day” records, they will appear before any “even” records on the same day number.