469,344 Members | 6,421 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

Quick and simple way to order a set of meetings by day of week

Okay, I have a database listing various meetings. The meetings have a
day of the week and a time (Say Sunday at 8:00). Now, given a set of
these meetings, how would I order them so that they would go Sunday,
Monday, Tuesday, Wednesday, Thursday, Friday. note these meetings don't
have dates, just day of week and time. Oh, and they're coming from a
MySQL database.
Dec 20 '05 #1
3 1096
John Meyer wrote:
MySQL database.


Please bring a little bit of life to comp.databases.mysql

--
E. Dronkert
Dec 20 '05 #2
John Meyer wrote:
Okay, I have a database listing various meetings. The meetings have a
day of the week and a time (Say Sunday at 8:00). Now, given a set of
these meetings, how would I order them so that they would go Sunday,
Monday, Tuesday, Wednesday, Thursday, Friday. note these meetings don't
have dates, just day of week and time. Oh, and they're coming from a
MySQL database.

create table daysofweek (weekdaynumber int, weekdayname varchar(9));
insert daysofweek values (0, 'Monday');
insert daysofweek values (1, 'Tuesday');
insert daysofweek values (2, 'Wednesday');
insert daysofweek values (3, 'Thursday');
insert daysofweek values (4, 'Friday');
insert daysofweek values (5, 'Saturday');
insert daysofweek values (6, 'Sunday');

Now link your tables together with daysofweek and ORDER BY
weekdaynumber.

If you want the week to start on Wednesdays
select ... order by ((weekdaynumber + 5) % 7)

Dec 20 '05 #3
Mara Guida wrote:
John Meyer wrote:
Okay, I have a database listing various meetings. The meetings have a
day of the week and a time (Say Sunday at 8:00). Now, given a set of
these meetings, how would I order them so that they would go Sunday,
Monday, Tuesday, Wednesday, Thursday, Friday. note these meetings don't
have dates, just day of week and time. Oh, and they're coming from a
MySQL database.


create table daysofweek (weekdaynumber int, weekdayname varchar(9));
insert daysofweek values (0, 'Monday');
insert daysofweek values (1, 'Tuesday');
insert daysofweek values (2, 'Wednesday');
insert daysofweek values (3, 'Thursday');
insert daysofweek values (4, 'Friday');
insert daysofweek values (5, 'Saturday');
insert daysofweek values (6, 'Sunday');

Now link your tables together with daysofweek and ORDER BY
weekdaynumber.


Thanks for pointing out an obvious and simple solution.
Dec 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.