如,update table1 set col='2012' haha='hello' where id='2014001'
update table1 set col='1009' haha='nihao' where id='2014003'
上面 这两行 执行之后,每一条需要5秒,总共需要10秒才能执行完.
如何合并为一条?
在网上找了好久,总结了一个相对简单的语句(有些语句是函数语句,有点晕),如下:
update table1 set col=(case id
when '2014001' then '2012'
when '2014003' then '1009' end),
haha=(case id
when '2014001' then 'hello'
when '2014003' then 'nihao' end)
where id in('2014001','2014003')
改成这个之后,还是需要5秒,但是,它只执行了一次,所以只需要5秒
最笨的方式就是把这么多条查询结果当成表,然后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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)