Efficiency in data statistics

Source: Internet
Author: User

I have been changing a statistical part of the project for the last two days. Some Opinions on the statistical efficiency are written here as a record.

 

1. Statistics sometimes encounter different query conditions in the same table, so you have to write many statistical statements to get the results. First of all: to ensure data correctness, we must not sacrifice accuracy for efficiency. My solution is to check the content that needs to be queried, use the content of this Part as a temporary table, and then sort it out through chained query.

2. Minimize the number of link queries in the statistics module. Link queries in the verified module reduce the efficiency of some queries.

For example, select T. sid, T. qymc, t1.dl _ count, t2.qy _ ybyh_count from (select Sid, qymc from base_qyxx where (isdeleted = 0 or isdeletedis null) and ID = '2013') tleft join (select userid, count (1) dl_count from sys_log_login lwhere L. logindate> = to_date ('20140901', 'yyyymmdd') and L. logindate <= to_date ('20140901', 'yyyymmdd') group by userid) t1on T. SID = t1.useridleft join (select qyid, count (1) qy_ybyh_countfrom hidden_danger_ybyhxx ybyh where (isdeletedis null or isdeleted = 0) and (zfjcid is null) and ybyh. cjsj> = to_date ('20140901', 'yyyymmdd') and ybyh. cjsj <= to_date ('20170101', 'yyyymmdd') group by qyid) t2on T. SID = t2.qyid

 

Efficiency in data statistics

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.