 |
รบกวนอยากให้ช่วยเขียน crosstab ลองเขียนแล้วไม่ได้ mysql |
|
 |
|
|
 |
 |
|
Code (SQL)
CREATE TABLE IF NOT EXISTS `person` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`position` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
--
-- Dumping data for table `person`
--
INSERT INTO `person` (`id`, `name`, `position`) VALUES
(1, 'นายกุ๊กไก่', 'ผู้จัดการ'),
(2, 'นางสาวกิ่ง', 'ผู้ช่วยฯ'),
(3, 'นางอร', 'ธุรการ');
-- --------------------------------------------------------
--
-- Table structure for table `working`
--
CREATE TABLE IF NOT EXISTS `working` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`person_id` int(10) unsigned DEFAULT NULL,
`work_date` date DEFAULT NULL,
`work_detail` varchar(250) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;
INSERT INTO `working` (`id`, `person_id`, `work_date`, `work_detail`) VALUES
(1, 1, '2016-10-10', 'ประชุม 10/2559'),
(2, 2, '2016-10-10', 'ประชุม 10/2559'),
(3, 1, '2016-10-11', 'อบรมคอมฯ'),
(4, 3, '2016-10-12', 'อบรมคอมฯ'),
(5, 3, '2016-10-13', 'อบรมคอมฯ'),
(6, 2, '2016-10-13', 'อบรมคอมฯ');
Quote:คำสั่งคิวรี่ครับ
select t1.id,t1.name,t1.position,group_concat(concat(work_date,':"',work_detail,'"') separator ' , ') as dailywork
from person t1 left join working t2 on t1.id=t2.person_id
group by t1.name
order by t1.id
Quote: id name position dayswork
1 นายกุ๊กไก่ ผู้จัดการ 2016-10-11:"อบรมคอมฯ" , 2016-10-10:"ประชุม 10/2559"
2 นางสาวกิ่ง ผู้ช่วยฯ 2016-10-13:"อบรมคอมฯ" , 2016-10-10:"ประชุม 10/2559"
3 นางอร ธุรการ 2016-10-13:"อบรมคอมฯ" , 2016-10-12:"อบรมคอมฯ"
ได้แบบใกล้เคียง เขียนให้ดูเป็นแนวทาง ลองเอาไปปรับดูครับ
|
 |
 |
 |
 |
Date :
2016-10-12 13:05:01 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตารางการทำงานแยกเป็นคอลัมภ์ได้ไหมคะทำไม่เป็น

|
 |
 |
 |
 |
Date :
2016-10-12 14:20:58 |
By :
noonaming |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|