作者:手机用户2502853881 | 来源:互联网 | 2018-04-25 23:10
请教下各位大神,mysqupdate数据优化遇到的问题是这样的。表a有2个字段,ready_count,download_count表b是统计表,有type,id两个表的储存引擎都是MYISAM需要把表b的数据count(1)groupby(type)之后update到表a的那两个字段中。我现在的SQL是这样的:updatea_t1set_t1.ready_count(SELECTcount(1)FROMb_t2WHERE_t2.tid...
mysqlselect优化数据update select
请教下各位大神,mysq update数据优化
遇到的问题是这样的。
表a有2个字段,ready_count,download_count
表b是统计表,有type,id
两个表的储存引擎都是MYISAM
需要把表b的数据count(1) group by(type)之后update到表a的那两个字段中。
我现在的SQL是这样的:
update a _t1
set
_t1.ready_count = (
SELECT count(1) FROM b _t2 WHERE _t2.tid = _t1.id and _t2.type = 1
),
_t1.download_count = (
SELECT count(1) FROM b _t2 WHERE _t2.tid = _t1.id and _t2.type = 2
),