count concatenate column in mysql -
i want this, case not function. example table:
date model no line range lot status 2010-08-01 kd-g435 1 01 1-100 013a accept 2010-08-01 kd-g435 2 01 1-100 013a accept 2010-08-01 kw-tc800 1 01 1-200 001a null 2010-08-01 kw-tc800 2 01 1-200 001a null 2010-08-01 kw-tc800 3 01 1-200 001a null 2010-08-01 kd-r411 1 05 1-100 021a reject 2010-08-01 kd-r411 2 05 1-100 021a reject create table if not exists `inspection_report` ( `id` int(11) not null auto_increment, `model` varchar(14) not null, `serial_number` varchar(8) not null, `lot_no` varchar(6) not null, `line` char(5) not null, `shift` char(1) not null, `inspection_datetime` datetime not null, `range_sampling` varchar(19) not null, `packing` char(2) not null, `accesories` char(2) not null, `appearance` char(2) not null, `tuner` char(2) not null, `general_operation` char(2) not null, `remark` text not null, `nik` int(5) not null, `s` int(11) not null, `a` int(11) not null, `b` int(11) not null, `c` int(11) not null, `status` varchar(6) not null, primary key (`id`), unique key `model` (`model`,`serial_number`,`lot_no`,`line`) ) engine=myisam default charset=latin1 auto_increment=84 ; -- -- dumping data table `inspection_report` -- insert `inspection_report` (`id`, `model`, `serial_number`, `lot_no`, `line`, `shift`, `inspection_datetime`, `range_sampling`, `packing`, `accesories`, `appearance`, `tuner`, `general_operation`, `remark`, `nik`, `s`, `a`, `b`, `c`, `status`) values (79, 'kd-g435und', '135x0002', '012a', 'fa 01', 'a', '2010-08-01 14:26:35', '135x0001-135x0100', 'ok', 'ok', 'ng', 'ok', 'ok', '2ver-m302', 25158, 0, 1, 1, 0, 'accept'), (78, 'kd-g435und', '135x0001', '012a', 'fa 01', 'a', '2010-08-01 14:24:35', '135x0001-135x0100', 'ok', 'ok', 'ng', 'ok', 'ok', '2ver-m302', 25158, 0, 0, 1, 0, 'accept'), (77, 'kw-tc800und', '135x0003', '011a', 'fa 01', 'a', '2010-08-01 09:12:01', '135x0001-135x0100', 'ok', 'ok', 'ok', 'ok', 'ok', 'test', 25158, 0, 0, 0, 0, ''), (76, 'kw-tc800und', '135x0002', '011a', 'fa 01', 'a', '2010-08-01 09:10:01', '135x0001-135x0100', 'ok', 'ok', 'ok', 'ok', 'ok', 'test', 25158, 0, 0, 0, 0, ''), (75, 'kw-tc800und', '135x0001', '011a', 'fa 01', 'a', '2010-08-01 09:08:01', '135x0001-135x0100', 'ok', 'ok', 'ok', 'ok', 'ok', 'test', 25158, 0, 0, 0, 0, ''), (63, 'kd-r411ed', '135x0001', '022a', 'fa 05', 'a', '2010-08-01 16:24:04', '135v0001-135v0200', 'ok', 'ok', 'ng', 'ok', 'ok', 'ver-r105', 25158, 0, 1, 0, 0, 'reject'), (65, 'kd-r411ed', '135x0002', '022a', 'fa 05', 'a', '2010-08-01 09:08:01', '135v0001-135v0200', 'ok', 'ok', 'ng', 'ng', 'ok', 'ver-r105', 25158, 0, 1, 1, 0, 'reject'), (66, 'kd-g435und', '135x0001', '023a', 'fa 05', 'a', '2010-09-02 14:24:35', '135x0001-135x0100', 'ok', 'ok', 'ng', 'ok', 'ok', '2ver-m302', 25158, 0, 0, 1, 0, 'accept'), (67, 'kw-tc800und', '135x0001', '025a', 'fa 07', 'a', '2010-10-01 09:08:01', '135x0001-135x0100', 'ok', 'ok', 'ok', 'ok', 'ok', 'test', 25158, 0, 0, 0, 0, ''), (80, 'kd-g435und', '135x0001', '013a', 'fa 02', 'a', '2010-09-01 14:24:35', '135x0001-135x0200', 'ok', 'ok', 'ng', 'ok', 'ok', '2ver-m302', 25158, 0, 0, 1, 0, 'accept'), (81, 'kd-g435und', '135x0002', '013a', 'fa 02', 'a', '2010-09-01 14:28:35', '135x0001-135x0200', 'ok', 'ok', 'ok', 'ok', 'ok', '2ver-m302', 25158, 0, 0, 0, 0, ''), (82, 'kd-r411ed', '135x0002', '014a', 'fa 03', 'a', '2010-09-01 09:08:01', '135v0001-135v0200', 'ok', 'ok', 'ng', 'ng', 'ok', 'ver-r105', 25158, 0, 1, 1, 0, 'reject'), (83, 'kd-r411ed', '135x0001', '015a', 'fa 05', 'a', '2010-09-01 16:24:04', '135x9901-135v0000', 'ok', 'ok', 'ng', 'ok', 'ok', 'ver-r105', 25158, 0, 1, 0, 0, 'reject');
edit
i've tried query:
select date(inspection_datetime), model, count(distinct(concat(range_sampling,model,line,lot_no))) lot_qty, if(status !='reject',1,0) accept, if(status ='reject',1,0) reject
from inspection_report group date(inspection_datetime), model
and result like:
date(inspection_datetime) model lot_qty accept reject 2010-08-01 kd-g435und 1 1 0 2010-08-01 kd-r411ed 1 0 1 2010-08-01 kw-tc800und 1 1 0 2010-09-01 kd-g435und 1 1 0 2010-09-01 kd-r411ed 2 0 1 2010-09-02 kd-g435und 1 1 0 2010-10-01 kw-tc800und 1 1 0
i want make table like:
date lot_qty accept reject 2010-08-01 3 2 1 //count in same date become 1 2010-09-01 3 1 1 //count in same date become 1 2010-09-02 1 1 0 2010-10-01 1 1 0
this query near answer, can't count accept , reject result grouping in same date.try query.
answer:
select x.insdate, sum(x.lot_qty), sum(x.accept), sum(x.reject) (select date(inspection_datetime) insdate, model, count(distinct(concat(range_sampling,model,line,lot_no))) lot_qty, if(status !='reject',1,0) accept, if(status ='reject',1,0) reject inspection_report group date(inspection_datetime), model, line, range_sampling, lot_no) x group x.insdate
Comments
Post a Comment