Home > Database > Mysql Tutorial > body text

mysql-MySql 数据统计Update Select优化

WBOY
Release: 2016-06-06 09:38:39
Original
1313 people have browsed it

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
),

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template