Mysql-MySql data statistics UpdateSelect optimization

Source: Internet
Author: User
For more information, see mysqupdate data optimization. Table a has two fields: ready_count and download_count. Table B is a statistical table. the storage engines of tables with type and id are MYISAM. you need to count (1) groupby (type) the data of Table B) then update to the two fields in Table. My current SQL statement is like this: updatea_t1set_t1.ready_count (SELECTcount (1) FROMb_t2WHERE_t2.tid... mysqlselect optimize data update select

Ask the experts to optimize mysq update data
This is the problem.
Table a has two fields: ready_count and download_count.
Table B is a statistical table with type and id.
The storage engines of both tables are MYISAM.
You need to update the data count (1) group by (type) in Table B to the two fields in Table.

My current SQL statement is as follows:
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
),

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.