MySQL count標量子查詢怎么改left join,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
成都創(chuàng)新互聯(lián)公司專注于中大型企業(yè)的成都網(wǎng)站建設(shè)、做網(wǎng)站和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計客戶上千家,服務(wù)滿意度達97%。幫助廣大客戶順利對接上互聯(lián)網(wǎng)浪潮,準確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運用,我們將一直專注成都品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開發(fā),在前進的路上,與客戶一起成長!
SELECT homepageId, userId, homepagesummary, totalviews, totalleadpercents, totalappointments, homepagestatus, linkphone, imagepath, createtime, updatetime, recommendtime, sortcode, designerimagepath, isrecommend, ( SELECT count(*) FROM homepagexxxrelation WHERE homepageid = h.homepageid AND groundingstatus = 0 ) AS totalxxx, ( SELECT count(*) FROM homepagexxxrelation WHERE homepageid = h.homepageid AND groundingstatus = 0 AND Createtime >= DATE_SUB(sysdate(), INTERVAL 7 DAY) ) AS weektotalxxx FROM designerhomepage h WHERE 1 = 1 and isrecommend=1 order by weektotalxxx DESC, homepageid DESC; 優(yōu)化后: SELECT h.homepageId, h.userId, h.homepagesummary, h.totalviews, h.totalleadpercents, h.totalappointments, h.homepagestatus, h.linkphone, h.imagepath, h.createtime, h.updatetime, h.recommendtime, h.sortcode, h.designerimagepath, h.isrecommend, ifnull(h3.cnt2,0) AS totalscheme, ifnull(h3.cnt1,0) AS weektotalxxx FROM designerhomepage h LEFT JOIN ( SELECT Homepageid, sum(case when HP.Createtime >= DATE_SUB(sysdate(), INTERVAL 7 DAY) then 1 else 0 end) cnt1, count(*) cnt2 FROM homepagexxxrelation hp WHERE HP.groundingstatus = 0 GROUP BY Homepageid ) h3 ON h3.homepageid = h.homepageid WHERE 1 = 1 and isrecommend=1 ORDER BY weektotalxxx DESC, homepageid DESC;
看完上述內(nèi)容,你們掌握MYSQL count標量子查詢怎么改left join的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!