Home > database >  A large number of union all related how to improve the statistics? A temporary table can only be use
A large number of union all related how to improve the statistics? A temporary table can only be use

Time:09-26

Needs and provide more than one result for the front-end of statistics, data from many different tables, using a union all now, but if the underlying data table more than 10000 data, the query efficiency is very low, need 10 seconds or so, can you tell me the Montana you like need the statistical result how to deal with the
Thank you

 

SELECT count (1) the from t_user_quanrl where qid=16 and roles & gt; 5
Union all (select count (1) the from ` sys_user ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and (DATE (NOW ())=DATE (a.r egdate)))

Union all (select count (1) the from ` sys_user ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and a.u gender=1)

Union all (select count (1) the from ` sys_user ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and a.u gender=2)

Union all (select count (1) the from ` t_user_loginhis ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` uid `=b. ` userid ` and (DATE (NOW ())=DATE (Dr. DATE)))

Union all (SELECT count (1) the from ` t_user_clinc ` a where clause (datediff (NOW (), clincdate)=0) and a. clsids=16)

Union all (select count (1) the from ` t_user_mentalhis ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` muid `=b. ` userid ` and (DATE (NOW ())=DATE (arjun DATE)))

Union all (select count (1) the from ` t_user_mentalhis ` a inner join tmp_ql b on a. ` muid `=b. ` userid `) union all (select count (1) the from ` t_user_iot_examdx ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and (DATE (NOW ())=DATE (a.c DATE)))

Union all (select count (1) the from tmp_mhis a inner join tmp_ql1 b on a. ` muid `=b. ` userid `) union all (select count (1) the from ` sys_user ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and year (regdate)=year (curdate ()) and (the month (regdate)=month (curdate ())))

Union all (select count (1) the from ` sys_user ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and year (regdate)=year (curdate ()) and the month (regdate)=month (curdate ()) and (week (regdate)=week (curdate ())))

Union all (select sum (ubalance - 5) from ` t_user_account ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid `)

Union all (select sum (realpayfee) from ` t_user_paybill ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` uid `=b. ` userid ` and (DATE (NOW ())=DATE (a. uydate)))

Union all (select sum (realpayfee) from ` t_user_paybill ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` uid `=b. ` userid ` and year (buydate)=year (curdate ()) and (the month (buydate)=month (curdate ())))

Union all (select sum (transfee) from ` t_user_payment_bill ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and payflag=0 and (DATE (NOW ())=DATE (a.u cdate)))

Union all (select sum (transfee) from ` t_user_payment_bill ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and payflag=0 and year (ucdate)=year (curdate ()) and (the month (ucdate)=month (curdate ())))

Union all (select sum (transfee) from ` t_user_payment_bill ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and payflag=1 and year (ucdate)=year (curdate ()) and (the month (ucdate)=month (curdate ())))

Union all (select count (1) the from ` sys_user_hext ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and isbp=1)

Union all (select count (1) the from ` sys_user_hext ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and islip=1)

Union all (select count (1) the from ` sys_user_hext ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and isDiabet=1)

Union all (select count (1) the from ` t_user_iot_ecgx ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` userid `=b. ` userid ` and ECGRESULT like '% exception %')

Union all (select count (1) the from ` t_user_mentalhis ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` muid `=b. ` userid ` and ` vwarnlevel `=3 and year (mdate)=year (curdate ()) and (the month (mdate)=month (curdate ())))

Union all (select count (1) the from ` t_user_mentalhis ` a inner join (select userid from t_user_quanrl where qid=16 and roles & gt; 5) b on a. ` muid `=b. ` userid ` and ` vwarnlevel `=3 and year (mdate)=year (curdate ()) and (the month (mdate)=month (' 2020-08-26 ')))


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related