需要給前端提供一個多結果的統計資料,來自很多不同的資料表, 現在使用的是 union all ,但如果基礎資料表超過 10000條資料的時候,查詢效率很低,需要 10秒左右,請問各位大拿像需要這種統計結果的時候一般如何處理
謝謝
SELECT count(1) from t_user_quanrl where qid = 16 and roles > 5
union all(select count(1) from `sys_user` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and (DATE(NOW()) = DATE(a.regdate)))
union all(select count(1) from `sys_user` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and a.ugender = 1)
union all(select count(1) from `sys_user` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and a.ugender = 2)
union all(select count(1) from `t_user_loginhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`uid` = b.`userid` and(DATE(NOW()) = DATE(a.vdate)))
union all(SELECT count(1) from `t_user_clinc` a where (datediff(NOW(), clincdate) = 0) and a.bclsid = 16)
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and(DATE(NOW()) = DATE(a.mdate)))
union all(select count(1) from `t_user_mentalhis` a inner join tmp_ql b on a.`muid` = b.`userid` ) union all(select count(1) from `t_user_iot_examdx` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and(DATE(NOW()) = DATE(a.cdate)))
union all(select count(1) from tmp_mhis a inner join tmp_ql1 b on a.`muid` = b.`userid` ) union all(select count(1) from `sys_user` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and year(regdate) = year(curdate()) and (month(regdate) = month(curdate())))
union all(select count(1) from `sys_user` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and year(regdate) = year(curdate()) and 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 > 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 > 5 ) b on a.`uid` = b.`userid` and (DATE(NOW()) = DATE(a.buydate)) )
union all(select sum(realpayfee) from `t_user_paybill` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`uid` = b.`userid` and year(buydate) = year(curdate()) and ( 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 > 5 ) b on a.`userid` = b.`userid` and payflag = 0 and(DATE(NOW()) = DATE(a.ucdate)))
union all(select sum(transfee) from `t_user_payment_bill` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and payflag = 0 and year(ucdate) = year(curdate()) and(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 > 5 ) b on a.`userid` = b.`userid` and payflag = 1 and year(ucdate) = year(curdate()) and (month(ucdate) = month(curdate())))
union all(select count(1) from `sys_user_hext` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and isbp = 1 )
union all(select count(1) from `sys_user_hext` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and islip = 1 )
union all(select count(1) from `sys_user_hext` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and isDiabet = 1 )
union all(select count(1) from `t_user_iot_ecgx` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`userid` = b.`userid` and ECGRESULT like '%例外%' )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 3 and year(mdate) = year(curdate()) and ( month(mdate) = month(curdate()) ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 3 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-08-26') ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 3 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-07-26') ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 4 and year(mdate) = year(curdate()) and ( month(mdate) = month(curdate()) ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 4 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-08-26') ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 4 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-07-26') ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 5 and year(mdate) = year(curdate()) and ( month(mdate) = month(curdate()) ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 5 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-08-26') ) )
union all(select count(1) from `t_user_mentalhis` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`muid` = b.`userid` and `vwarnlevel` = 5 and year(mdate) = year(curdate()) and ( month(mdate) = month('2020-07-26') ) )
union all(select count(1) from `sys_hservice_hypertension` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_hypertension` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_diabetes` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_diabetes` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_tuber_sf` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_tuber_sf` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_pregnant25` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_pregnant25` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_pregnant_born` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_pregnant_born` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_pregnant_b42` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_pregnant_b42` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`ARCHIVEID` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_babyfollow` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) )
union all(select count(1) from `sys_hservice_babyfollow` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) and (month(created_date) = month(curdate())) )
union all(select count(1) from `sys_hservice_healthinfo` a inner join(select userid from t_user_quanrl where qid = 16 and roles > 5 ) b on a.`archiveid` = b.`userid` and year(created_date) = year(curdate()) )
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/133064.html
標籤:MySQL
上一篇:如何根據句柄回傳視窗實體
