 |
ช่วยด้วยครับเรื่องรายงาน [FusionCharts Enterprise] |
|
 |
|
|
 |
 |
|
ฐานข้อมูล
Code (PHP)
CREATE TABLE `tb_request` (
`re_id` char(10) collate utf8_unicode_ci NOT NULL COMMENT 'รหัสการขอใช้งาน',
`re_date_go` date default NULL COMMENT 'วันเดินทางไป',
`re_time_go` time default NULL COMMENT 'เวลาเดินทางไป',
`re_date_back` date default NULL COMMENT 'วันเดินทางกลับ',
`re_time_back` time default NULL COMMENT 'เวลาเดินทางกลับ',
`zipcode_code` char(6) collate utf8_unicode_ci default NULL COMMENT 'จังหวัด',
`re_location` varchar(100) collate utf8_unicode_ci default NULL COMMENT 'สถานที่ไป',
`re_topic` varchar(100) collate utf8_unicode_ci default NULL COMMENT 'หัวข้อเดินทาง',
`re_apply` varchar(50) collate utf8_unicode_ci default NULL COMMENT 'นำไปใช้ในงาน',
`re_num` int(3) default NULL COMMENT 'จำนวนคน',
`car_id` char(10) collate utf8_unicode_ci default NULL COMMENT 'รหัสยานพาหนะ',
`per_id` char(10) collate utf8_unicode_ci NOT NULL COMMENT 'รหัสบุคลากร',
`re_date` date NOT NULL COMMENT 'วันที่ขอใช้งาน',
`re_num_save` char(10) collate utf8_unicode_ci NOT NULL COMMENT 'เลขที่บันทึกข้อความ',
`re_status` enum('w','a','n') collate utf8_unicode_ci NOT NULL default 'w' COMMENT 'w = รอผลการตรวจสอบ a = ผ่านการอนุมัติ n = ไม่ผ่านการอนุมัติ',
PRIMARY KEY (`re_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ตารางขอใช้งาน';
--
-- dump ตาราง `tb_request`
--
INSERT INTO `tb_request` VALUES ('RE00000001', '0000-00-00', '00:10:00', '0000-00-00', '00:05:00', '810000', 'asdf', 'asdf', 'asdf', 505, 'C0001', 'PER0000001', '2012-04-23', '', 'w');
INSERT INTO `tb_request` VALUES ('RE00000002', '0000-00-00', '00:00:00', '0000-00-00', '00:05:00', '810000', 'a', 'a', 'a', 1, 'C0001', 'PER0000001', '2012-01-25', '', 'w');
INSERT INTO `tb_request` VALUES ('RE00000003', '0000-00-00', '00:10:00', '0000-00-00', '00:10:00', '810000', 's', 's', 's', 1, 'C0001', 'PER0000001', '2012-01-25', '', 'w');
แล้วนี่ก็คือไฟล์ข้อมูลครับ
Download : Click!!!
อยากแสดงผลแบบนี้อะครับ

พอจะทำรายงานเป็นประจำปีได้หรือป่าวครับ
ผมอยากแสดงครบทั้ง 12 เดือนเลย
เดือนไหนไม่มีก็ให้เป็น 0
เดือนไหนมีก็ให้แสดงรวม(count)
ตามเดือนนั้น ๆ เลยอะครับ
เหมือนกับตัวอย่างที่ให้ไปอะครับ
ขอบคุณครับ
Tag : PHP, MySQL, Report Others
|
ประวัติการแก้ไข 2012-04-26 01:58:14 2012-04-26 01:58:54 2012-04-26 02:00:22 2012-04-26 05:15:29
|
 |
 |
 |
 |
Date :
2012-04-26 01:52:41 |
By :
iHacking |
View :
1257 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
select
`Year`,
sum(`Jan`) as `Jan`,
sum(`Feb`) as `Feb`,
sum(`Mar`) as `Mar`,
sum(`Apr`) as `Apr`,
sum(`May`) as `May`,
sum(`Jun`) as `Jun`,
sum(`Jul`) as `Jul`,
sum(`Aug`) as `Aug`,
sum(`Sep`) as `Sep`,
sum(`Oct`) as `Oct`,
sum(`Nov`) as `Nov`,
sum(`Dec`) as `Dec`,
sum(`Total`) as `Total`
from
(select year(`re_date`) as Year,
case month(`re_date`) when 1 then count(`re_date`) else null end as `Jan`,
case month(`re_date`) when 2 then count(`re_date`) else null end as `Feb`,
case month(`re_date`) when 3 then count(`re_date`) else null end as `Mar`,
case month(`re_date`) when 4 then count(`re_date`) else null end as `Apr`,
case month(`re_date`) when 5 then count(`re_date`) else null end as `May`,
case month(`re_date`) when 6 then count(`re_date`) else null end as `Jun`,
case month(`re_date`) when 7 then count(`re_date`) else null end as `Jul`,
case month(`re_date`) when 8 then count(`re_date`) else null end as `Aug`,
case month(`re_date`) when 9 then count(`re_date`) else null end as `Sep`,
case month(`re_date`) when 10 then count(`re_date`) else null end as `Oct`,
case month(`re_date`) when 11 then count(`re_date`) else null end as `Nov`,
case month(`re_date`) when 12 then count(`re_date`) else null end as `Dec`,
count(`re_date`) as Total
from tb_request group by year(`re_date`), month(`re_date`))
as temp group by Year
จับแนวได้แล้วครับ
ถ้าผมอยากแสดงเฉพาะ ปี 2012
ผมจะใส่ having ตรงไหนครับเนี่ย ลองดูหลายที่แล้วก็ยังไม่ได้
ต้องขอขอบคุณกระทู้นี้ https://www.thaicreate.com/php/forum/060188.html
ที่่เป็นแนวทางให้แต่ก็ยังติดเงื่อนไข
จะให้แสดงเฉพาะปีนั้น ๆ
ไม่รู้จะใส่ HAVING ตรงไหน
|
ประวัติการแก้ไข 2012-04-26 04:17:16
 |
 |
 |
 |
Date :
2012-04-26 04:11:59 |
By :
iHacking |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code
select
`Year`,
sum(`Jan`) as `Jan`,
sum(`Feb`) as `Feb`,
sum(`Mar`) as `Mar`,
sum(`Apr`) as `Apr`,
sum(`May`) as `May`,
sum(`Jun`) as `Jun`,
sum(`Jul`) as `Jul`,
sum(`Aug`) as `Aug`,
sum(`Sep`) as `Sep`,
sum(`Oct`) as `Oct`,
sum(`Nov`) as `Nov`,
sum(`Dec`) as `Dec`,
sum(`Total`) as `Total`
from
(select year(`re_date`) as Year,
case month(`re_date`) when 1 then count(`re_date`) else null end as `Jan`,
case month(`re_date`) when 2 then count(`re_date`) else null end as `Feb`,
case month(`re_date`) when 3 then count(`re_date`) else null end as `Mar`,
case month(`re_date`) when 4 then count(`re_date`) else null end as `Apr`,
case month(`re_date`) when 5 then count(`re_date`) else null end as `May`,
case month(`re_date`) when 6 then count(`re_date`) else null end as `Jun`,
case month(`re_date`) when 7 then count(`re_date`) else null end as `Jul`,
case month(`re_date`) when 8 then count(`re_date`) else null end as `Aug`,
case month(`re_date`) when 9 then count(`re_date`) else null end as `Sep`,
case month(`re_date`) when 10 then count(`re_date`) else null end as `Oct`,
case month(`re_date`) when 11 then count(`re_date`) else null end as `Nov`,
case month(`re_date`) when 12 then count(`re_date`) else null end as `Dec`,
count(`re_date`) as Total
from tb_request group by year(`re_date`), month(`re_date`))
as temp where `Year` = 2012 group by `Year`
|
 |
 |
 |
 |
Date :
2012-04-26 04:33:52 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|