mysql 多条语句,怎么判断其中一条执行错误,就执行回滚
写一个存储过程,在存储过程里写一个事物,再把你要的mysql 多条语句写在事物里面就行了,要用的时候调用一下存储过程.大致格式是这样的:drop procedure if exists accessCount; delimiter $create procedure accessCount()BEGIN DECLARE t_error INTEGER DEFAULT 0;/*设置错误增量*/ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; START TRANSACTION;/*开启事物*/xxxx(你的语句)IF t_error = 1 THEN /*执行失败回滚*/ROLLBACK; ELSE COMMIT; END IF;end $delimiter ;。
mysql查询语句 多条合并
最笨的方式就是把这么多条查询结果当成表,然后select全部,虽然笛卡尔积,但是每个查询都只有一条记录。
select * from
(select count(t1.fXM)as A1 from KJ_KJHDRYMXB t1 where t1.fDW = 'a部' )a,
(select count(t2.fJSZW)AS A2 from KJ_KJHDRYMXB t2 where t2.fJSZW = '项目人员' and t2.fDW = 'a部')b,
(select count(t3.fJSZW)AS A3 from KJ_KJHDRYMXB t3 where (t3.fJSZW = '服务人员'or t3.fJSZW = '管理人员') and t3.fDW = 'a部')c,
(select count(t31.fXB)AS A4 from KJ_KJHDRYMXB t31 where t31.fXB = '女' and t31.fDW = 'a部')d
(select count(t4.fZC)AS A5 from KJ_KJHDRYMXB t4 where (t4.fZC = '高级职称'or t4.fZC = '中级职称')and t4.fDW = 'a部')d,
(select count(t5.fXM)AS A6 from KJ_KJHDRYMXB t5 where t5.fDW = 'a部')e
(select count(t6.fXL)AS A7 from KJ_KJHDRYMXB t6 where t6.fXL = '博士'and t6.fDW = 'a部')f
(select count(t7.fXL)AS A8 from KJ_KJHDRYMXB t7 where t7.fXL = '硕士' and t7.fDW = 'a部')g
(select count(t8.fXL)AS A9 from KJ_KJHDRYMXB t8 where t8.fXL = '本科'and t8.fDW = 'a部')h