mysql实践3

select  sum(guid)  from `sqm`.`sqm_value_quality_station` WHERE result='PASS'
  GROUP BY station_code


sqmdc


select  count(guid),station_code  from `sqm`.`sqm_value_quality_station` WHERE result='PASS'
  GROUP BY day

select  count(guid), station_code  from `sqm`.`sqm_value_quality_station` WHERE result='PASS'
  GROUP BY station_code


INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('11', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');

INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('12', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('13', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('14', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('15', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('16', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('17', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('18', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('19', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('20', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');


INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('21', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('22', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('23', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('24', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('25', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('26', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('27', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('28', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('29', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('30', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');


INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('31', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('32', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('33', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('34', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('35', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('36', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('37', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('38', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('39', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');
INSERT INTO `sqm`.`sqm_value_quality_station` (`guid`, `date`, `year`, `month`, `day`, `supplier_code`, `module_code`, `work_order`, `line_code`, `station_code`, `serial_no`, `operator`, `result`, `generate_time`, `create_time`) VALUES ('40', '2011-10-28', '2011', '10', '28', 'sefawerr', 'werqr', 'weqrqwer', 'qwerwqer', 'station', 'asd', 'asdasd', 'PASS', '2011-10-21 13:55:32', '2011-10-21 13:55:32');


  select 
  val1.station_code beanKey,
  val1.fail beanValFail,
  val2.total beanValTotal
  from
  (
  select 
  count(guid)  fail ,
  station_code
  from
   `sqm`.`sqm_value_quality_station` 
  WHERE
  result='PASS'
  GROUP BY
  station_code
  ) 
  val1
  left join
  (
  select 
  count(guid) total,
  station_code
  from
   `sqm`.`sqm_value_quality_station`
  GROUP BY
  station_code
  ) 
  val2
  on 
  val1.station_code = val2.station_code

 select 
  val1.day beanKey,
  val1.fail beanValFail,
  val2.total beanValTotal
  from
  (
  select 
  count(guid)  fail ,
  day
  from
   `sqm`.`sqm_value_quality_station` 
  WHERE
  result='PASS'
  GROUP BY
  day
  ) 
  val1
  left join
  (
  select 
  count(guid) total,
  day
  from
   `sqm`.`sqm_value_quality_station`
  GROUP BY
  day
  ) 
  val2
  on 
  val1.day = val2.day

原文地址:https://www.cnblogs.com/mount/p/2258311.html