Mysql statistics retention rate

Source: Internet
Author: User

Mysql statistics retention rate SQL code begin declare I int; declare numareaId int (10); declare currentareaId int (10); SELECT COUNT (areaId), MIN (areaId) INTO @, @ B FROM option_area_info; SET numareaId = @ a; SET currentareaId = @ B; loop1: WHILE numareaId> 0 do set @ AID = currentareaId; SET I = 1; while I <8 do if exists (select * from statistics_player_l where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day) and areaId = @ AID) then update statistics_player_l set oneDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 1 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 2 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set twoDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 2 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 3 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set threeDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 3 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 4 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set fourDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 4 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 5 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set fiveDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 5 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 6 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set sixDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 6 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 7 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day ); update statistics_player_l set sevenDayPlayer = (select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) and loginTime> = date_add (date_sub (curdate (), interval I day), interval 7 day) and loginTime <date_add (date_sub (curdate (), interval I day ), interval 8 day) and areaId = @ AID)/(select count (distinct playerId) from log_login where registerTime = date_sub (curdate (), interval I day) * 100) where createTime> = date_sub (curdate (), interval I day) and createTime <date_sub (curdate (), interval I-1 day); end if; SET I = I + 1; end while; SET numareaId = numareaId-1; SET currentareaId = currentareaId + 1; end while loop1; end

Related Article

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.