I've got a task at work to create a calendar view in mysql. The frontend used is filemaker which doesn't support query results. The only workround is to create a view and use as table.
What I need is a full calendar view for each date found in appt table for each clinic. Meaning if there is an appoinment in appt table for a given date, I need to produce a full calendar view with all timeslots from timeslots table and then selecting appt rows as columns corresponding each timeslot or null. I'm attached pdf of end result. Don't know where to start.
I did some googling and found this thread which is similar to what I need but its for only date specified in the where clause. There are preety good senior members on this site. Hoping someone will be able to help me.
Thank you all,
http://forums.mysql.com/read.php?108...327#msg-395327
Select ap.id, ts.time_slot, ap.clinic, ap.appt_date,
If(ap.doctor='SX', ap.client, null) as Doc_1,
If(ap.doctor='AOH', ap.client, null) as Doc_2,
If(ap.doctor='MAN', ap.client, null) as Doc_3,
If(ap.doctor='DBC', ap.client, null) as Doc_4
from timeslots ts left outer join appt ap on ts.time_slot = ap.time_slot
and ts.clinic = ap.clinic
Group By ts.time_slot, ts.clinic
Order By ts.id
CREATE DATABASE `temp`
CHARACTER SET 'latin1'
COLLATE 'latin1_swedish_ci';
USE `temp`;
DROP TABLE IF EXISTS `appt`;
CREATE TABLE `appt` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`clinic` char(1) CHARACTER SET utf8 DEFAULT NULL,
`doctor` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
`appt_date` date DEFAULT NULL,
`time_slot` varchar(20) DEFAULT NULL,
`client` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `timeslots`;
CREATE TABLE `timeslots` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`clinic` char(1) DEFAULT NULL,
`time_slot` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
INSERT INTO `appt` (`id`, `clinic`, `doctor`, `appt_date`, `time_slot`, `client`) VALUES
(1,'a','SX','2010-11-24','8:00 am','Bobbie Smith\rTest'),
(2,'a','AOH','2010-11-24','8:30 am','Molly Matthews\rGot gammy leg'),
(3,'a','MAN','2010-11-24','9:00 am','client 1'),
(4,'a','MAN','2010-11-24','9:30 am','client 2'),
(5,'a','MAN','2010-11-24','10:00 am','client 3'),
(6,'a','MAN','2010-11-24','11:00 am','client 4'),
(7,'a','MAN','2010-11-24','11:30 am','client 5'),
(8,'a','MAN','2010-11-24','12:00 pm','client 6'),
(9,'a','MAN','2010-11-24','12:30 pm','client 7'),
(10,'a','MAN','2010-11-24','1:00 pm','client 8'),
(11,'a','MAN','2010-11-24','1:30 pm','client 9'),
(12,'a','MAN','2010-11-24','02:00 pm','client 10'),
(13,'a','MAN','2010-11-24','02:30 pm','client 11'),
(14,'a','DBC','2010-11-24','8:30 am','Digby Smith\rjhgthjju'),
(15,'a','MAN','2010-11-24','10:30 am','Jake Smith\rStandard Consultation'),
(16,'b','SX','2010-11-24','8:00 am','Bobbie Smith\rTest'),
(17,'b','AOH','2010-11-24','8:30 am','Molly Matthews\rGot gammy leg'),
(18,'b','MAN','2010-11-24','9:00 am','client 1'),
(19,'b','MAN','2010-11-24','9:30 am','client 2'),
(20,'b','MAN','2010-11-24','10:00 am','client 3'),
(21,'b','MAN','2010-11-24','11:00 am','client 4'),
(22,'b','MAN','2010-11-24','11:30 am','client 5'),
(23,'b','MAN','2010-11-24','12:00 pm','client 6'),
(24,'b','MAN','2010-11-24','12:30 pm','client 7'),
(25,'b','MAN','2010-11-24','1:00 pm','client 8'),
(26,'b','MAN','2010-11-24','1:30 pm','client 9'),
(27,'b','MAN','2010-11-24','02:00 pm','client 10'),
(28,'b','MAN','2010-11-24','02:30 pm','client 11'),
(29,'b','DBC','2010-11-24','8:30 am','Digby Smith\rjhgthjju'),
(30,'b','MAN','2010-11-24','10:30 am','Jake Smith\rStandard Consultation'),
(31,'a','SX','2010-11-25','8:00 am','Bobbie Smith\rTest'),
(32,'a','AOH','2010-11-25','8:30 am','Molly Matthews\rGot gammy leg'),
(33,'a','MAN','2010-11-25','9:00 am','client 1'),
(34,'a','MAN','2010-11-25','9:30 am','client 2'),
(35,'a','MAN','2010-11-25','10:00 am','client 3'),
(36,'a','MAN','2010-11-25','11:00 am','client 4'),
(37,'a','MAN','2010-11-25','11:30 am','client 5'),
(38,'a','MAN','2010-11-25','12:00 pm','client 6'),
(39,'a','MAN','2010-11-25','12:30 pm','client 7'),
(40,'a','MAN','2010-11-25','1:00 pm','client 8'),
(41,'a','MAN','2010-11-25','1:30 pm','client 9'),
(42,'a','MAN','2010-11-25','02:00 pm','client 10'),
(43,'a','MAN','2010-11-25','02:30 pm','client 11'),
(44,'a','DBC','2010-11-25','8:30 am','Digby Smith\rjhgthjju'),
(45,'a','MAN','2010-11-25','10:30 am','Jake Smith\rStandard Consultation'),
(46,'b','SX','2010-11-25','8:00 am','Bobbie Smith\rTest'),
(47,'b','AOH','2010-11-25','8:30 am','Molly Matthews\rGot gammy leg'),
(48,'b','MAN','2010-11-25','9:00 am','client 1'),
(49,'b','MAN','2010-11-25','9:30 am','client 2'),
(50,'b','MAN','2010-11-25','10:00 am','client 3'),
(51,'b','MAN','2010-11-25','11:00 am','client 4'),
(52,'b','MAN','2010-11-25','11:30 am','client 5'),
(53,'b','MAN','2010-11-25','12:00 pm','client 6'),
(54,'b','MAN','2010-11-25','12:30 pm','client 7'),
(55,'b','MAN','2010-11-25','1:00 pm','client 8'),
(56,'b','MAN','2010-11-25','1:30 pm','client 9'),
(57,'b','MAN','2010-11-25','02:00 pm','client 10'),
(58,'b','MAN','2010-11-25','02:30 pm','client 11'),
(59,'b','DBC','2010-11-25','8:30 am','Digby Smith\rjhgthjju'),
(60,'b','MAN','2010-11-25','10:30 am','Jake Smith\rStandard Consultation');
COMMIT;
INSERT INTO `timeslots` (`id`, `clinic`, `time_slot`) VALUES
(1,'a','09:00 am'),
(2,'a','09:30 am'),
(3,'a','10:00 am'),
(4,'a','10:30 am'),
(5,'a','11:00 am'),
(6,'a','11:30 am'),
(7,'a','12:00 pm'),
(8,'a','12:30 pm'),
(9,'a','01:00 pm'),
(10,'a','01:30 pm'),
(11,'a','02:00 pm'),
(12,'a','02:30 pm'),
(13,'a','03:00 pm'),
(14,'a','03:30 pm'),
(15,'a','04:00 pm'),
(16,'a','04:30 pm'),
(17,'a','05:00 pm'),
(18,'b','09:00 am'),
(19,'b','09:30 am'),
(20,'b','10:00 am'),
(21,'b','10:30 am'),
(22,'b','11:00 am'),
(23,'b','11:30 am'),
(24,'b','12:00 pm'),
(25,'b','12:30 pm'),
(26,'b','01:00 pm'),
(27,'b','01:30 pm'),
(28,'b','02:00 pm'),
(29,'b','02:30 pm'),
(30,'b','03:00 pm'),
(31,'b','03:30 pm'),
(32,'b','04:00 pm'),
(33,'b','04:30 pm'),
(34,'b','05:00 pm');
COMMIT;





Bookmarks