MYSQL错误1172(4200):结果由我的一行组成

时间:2018-01-30 04:41:20

标签: mysql

我希望有人可以帮我解决在尝试根据Inspection.score更新Component.status时继续收到的错误。我正在尝试创建一个触发器或其他方法来将Component.status更新为" Ready"如果Inspection.score> = 90,则Component.status为"可用"当Inspection.score是< = 90且> = 75,而Component.status到" not-ready"当Inspection.score为< = 75时,检查每个组件后。表格详情和相关数据如下:

create table Inspection(
inspection_id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
inspector_id int,
component_id int,
score int,
description varchar(4000),
inspection_date Date,
foreign key (inspector_id) references Employee(employee_id),
foreign key (component_id) references Component(component_id)
);

create table Component(
component_id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
owner_id int,
name varchar(255),
version varchar(255),
language enum('C', 'C++','C#','Java','PHP','Python','assembly'),
status varchar(255) NOT NULL,
size int,
foreign key (owner_id) references Employee(employee_id)
);

insert into Component(component_id, name, version, size, language, owner_id) 
values
(1, "Keyboard Driver", "K11", 1200, "C", 10100),
(2, "Touch Screen Driver", "T00", 4000, "C++", 10100),
(3, "Dbase Interface", "D00", 2500, "C++", 10200),
(4, "Dbase Interface", "D01", 2500, "C++", 10300),
(5, "Chart Generator", "C11", 6500, "Java", 10200),
(6, "Pen Driver", "P01", 3575, "C", 10700),
(7, "Math Unit", "A01", 5000, "C", 10200),
(8, "Math Unit", "A02", 3500, "Java", 10200);

insert into Inspection(component_id, inspection_date, inspector_id, score, 
description) values
(1, "2010/02/14", 10100, 100, "legacy code which is already approved"),
(2, "2017/06/01", 10200, 95, "initial release ready for usage"),
(3, "2010/02/22", 10100, 55, "too many hard coded parameters, the software 
must be more maintainable and configurable because we want to use it in 
other products."),
(3, "2010/02/24", 10100, 78, "improved, but only handles DB2 format"),
(3, "2010/02/26", 10100, 95, "Okay, handles DB3 format."),
(3, "2010/02/28", 10100, 100, "satisfied"),
(4, "2011/05/01", 10200, 100, "Okay ready for use"),
(6, "2017/07/15", 10300, 80, "Okay ready for beta testing"),
(7, "2014/06/10", 10100, 90, "almost ready"),
(8, "2014/06/15", 10100, 70, "Accuracy problems!"),
(8, "2014/06/30", 10100, 100, "Okay problems fixed"),
(8, "2016/11/02", 10700, 100, "re-review for new employee to gain experience 
in the process.");

任何建议或建议都会非常有用,因为到目前为止我的所有尝试都导致了ERROR 1172(4200):结果由我的一行组成。

以下是我一直使用的触发器:

   delimiter ;;

   create trigger component_status
   after insert on Inspection
   for each row

   begin
   declare x int;
   select score from Inspection having MAX(inspection_date) into x;

   if x<75 then
   insert into Component(status) values ("not-ready");

   elseif  x>74 and x<90 then
   insert into Component(status) values ("usable");

   else
   insert into Component(status) values ("Ready");
   end if;
   end;;

   delimiter ;

0 个答案:

没有答案