mysql解题器_mysql触发器,答题记录表同步教学跟踪(用户列表)

DELIMITER ||

DROP TRIGGER IF EXISTS t_afterinsert_on_tab1 ||

CREATE TRIGGER t_afterinsert_on_tab1 AFTER INSERT

ON online_answerrecord FOREACH ROWBEGIN

--判断数据库中有无此记录,有,修改,无,新增

SET @count =(SELECT

COUNT(1)FROMonline_papercompletion_userWHERE USERID =new.useridAND ORDERID =new.orderid) ;--设置考试类型--SET @examinationtype = new.examinationtype;--强化总题数量--SET @qianghuatype = 0;--章节总题数量--SET @zhangjietype = 0;--预测总题数量--SET @yucetype = 0;--章节完成数量

SET @zhangjiewancheng = 0;--强化完成数量

SET @qianghuawancheng = 0;--预测完成数量

SET @yucewancheng = 0;--是否正确--SET @iscorrect = 0;

--设置章节试题(正确数)

SET @zhangjiezhengque = 0;--设置章节错误(错误数)

SET @zhangjiecuowu = 0;--强化试题(正确数)

SET @zhangjiezhengque = 0;--强化试题(错误数)

SET @qianghuacuowu = 0;--预测试题(正确数)

SET @yucezhengque = 0;--预测试题(错误数)--set @yucecuowu = 0 ;

--如果答题正确 暂定0是正确--IF new.Iscorrect = '0' THEN

--(

IF new.examinationtype = '强化试卷'

AND new.Iscorrect = '0'

THEN SET @qianghuawancheng = '1';SET @qianghuazhengque = '1';

ELSEIF new.examinationtype= '章节试卷'

AND new.Iscorrect = '0'

THEN SET @zhangjiewancheng = '1';SET @zhangjiezhengque = '1';

ELSEIF new.examinationtype= '预测试卷'

AND new.Iscorrect = '0'

THEN SET @yucewancheng = '1';SET @yucezhengque = '1';

ELSEIF new.examinationtype= '强化试卷'

AND new.Iscorrect = '1'

THEN SET @qianghuawancheng = '1';SET @qianghuacuowu1 = '1';

ELSEIF new.examinationtype= '章节试卷'

AND new.Iscorrect = '1'

THEN SET @zhangjiewancheng = '1';SET @zhangjiecuowu = '1';

ELSEIF new.examinationtype= '预测试卷'

AND new.Iscorrect = '1'

THEN SET @yucewancheng = '1';SET @yucecuowu = '1';END IF;--)

--END if;

IF @count = 0

THEN

INSERT INTOonline_papercompletion_user (

id,

name1,

name2,

createtime,

userid,

personlname,

sysuserid,

sysusername,

registrationsituation,

curriculum_name,

examinationtype,

examinationdate,

examinationaddress,

phonenumber,

z_totalquestions,

z_totalcomplete,

q_totalquestions,

q_totalcomplete,

c_totalquestions,

c_totalcomplete,

bysituation,

score,

orderid,

z_totaltrue,

z_totalfalse,

q_totaltrue,

q_totalfalse,

c_totaltrue,

c_totalfalse

)VALUES(FLOOR(1 + (RAND() * 400000)),

new.name1,

new.name2,

NOW(),

new.USERID,'','','','','',

new.examinationtype,

NOW(),'','','',@zhangjiewancheng,'',@qianghuawancheng,'',@yucewancheng,'','',

new.orderid,@zhangjiezhengque,@zhangjiecuowu,@qianghuazhengque,@qianghuacuowu,@yucezhengque,@yucecuowu) ;

ELSEIF@count > 0

THEN --set @zwancheng = cast((SELECT z_totalcomplete FROM online_papercompletion_user WHERE userid=new.userid AND orderid=new.orderid) as bigint);

UPDATEonline_papercompletion_userSET

--personlname,--sysuserid,--sysusername,--registrationsituation,--curriculum_name,--examinationtype,--examinationdate,--examinationaddress,--phonenumber,--z_totalquestions,

z_totalcomplete =(SELECTc.azFROM(

(SELECT

CONVERT(z_totalcomplete, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@zhangjiewancheng ASSIGNED),--q_totalquestions,

q_totalcomplete =(SELECTz.azFROM(

(SELECT

CONVERT(q_totalcomplete, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) z)+ CAST(@qianghuawancheng ASSIGNED),--c_totalquestions,

c_totalcomplete =(SELECTc.azFROM(

(SELECT

CONVERT(c_totalcomplete, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),--bysituation,--score,

z_totaltrue =(SELECTc.azFROM(

(SELECT

CONVERT(z_totaltrue, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),

z_totalfalse=(SELECTc.azFROM(

(SELECT

CONVERT(z_totalfalse, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),

q_totaltrue=(SELECTc.azFROM(

(SELECT

CONVERT(q_totaltrue, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),

q_totalfalse=(SELECTc.azFROM(

(SELECT

CONVERT(q_totalfalse, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),

c_totaltrue=(SELECTc.azFROM(

(SELECT

CONVERT(c_totaltrue, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED),

c_totalfalse=(SELECTc.azFROM(

(SELECT

CONVERT(c_totalfalse, SIGNED) azFROMonline_papercompletion_userWHERE userid =new.useridAND orderid =new.orderid)

) c)+ CAST(@yucewancheng ASSIGNED)WHERE userid =new.useridAND orderid =new.orderid ;END IF;END ||DELIMITER ;--测试数据

INSERT INTOzxks.online_answerrecord (

ANSWERRECORD_ID,

CREATETIME,

USERID,

ORDERID,

EXAMINATIONTYPE,

QUALIFICATIONS_ID,

CURRICULUM_ID,

ZID,

JID,

MID,

TID,

STRUCTUREPATH_NAME,

STRUCTUREPATH_CODE,

QUESTIONID,

ISCORRECT,

XUANXIANG,

PAGEID,

ISTAG,

FACILITYVALUE,

NAME1,

NAME2

)VALUES('2',

NOW(),'1','1','章节试卷','1','1','1','1','1','1','1','1','1','0','1','1',1,'1','1','1') ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值