域名计数:查询超时问题

时间:2019-02-08 20:40:28

标签: sql-server-2008

我正在计算要从查询中排除某些域名的域名,而我正在使用NOT IN。但是每次我尝试运行此查询时,它都会超时。有什么办法可以解决此问题,或者有其他方法可以编写此查询吗?

SELECT
    Domain = RIGHT(c.EmailAddress, LEN(c.EmailAddress) - CHARINDEX('@', c.EmailAddress))
    ,EmailCount = COUNT(DISTINCT c.EmailAddress)
    ,Address = COUNT(DISTINCT o.ShipAddress1 + ' ' + o.ShipAddress2)
FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
WHERE
    LEN(c.EmailAddress) > 0
    AND RIGHT(c.EmailAddress, LEN(c.EmailAddress) - CHARINDEX('@', c.EmailAddress))NOT IN ('gmail.com'
            ,'yahoo.com'
            ,'hotmail.com'
            ,'aol.com'
            ,'comcast.net'
            ,'sbcglobal.net'
            ,'msn.com'
            ,'verizon.net'
            ,'att.net'
            ,'bellsouth.net'
            ,'cox.net'
            ,'live.com'
            ,'onlinetechstores.com'
            ,'charter.net'
            ,'outlook.com'
            ,'earthlink.net'
            ,'optonline.net'
            ,'checkout.google.com'
            ,'me.com'
            ,'juno.com'
            ,'mac.com'
            ,'ymail.com'
            ,'windstream.net'
            ,'roadrunner.com'
            ,'embarqmail.com'
            ,'frontier.com'
            ,'icloud.com'
            ,'q.com'
            ,'frontiernet.net'
            ,'PACBELL.NET'
            ,'centurytel.net'
            ,'centurylink.net'
            ,'suddenlink.net'
            ,'netzero.net'
            ,'mail.com'
            ,'mindspring.com'
            ,'cableone.net'
            ,'rocketmail.com'
            ,'mchsi.com'
            ,'allstate.com'
            ,'ptd.net'
            ,'tds.net'
            ,'netscape.net'
            ,'netzero.com'
            ,'aim.com'
            ,'twc.com'
            ,'prodigy.net'
            ,'hughes.net'
            ,'ameritech.net'
            ,'rcn.com'
            ,'swbell.net'
            ,'fuse.net'
            ,'zoominternet.net'
            ,'inbox.com'
            ,'sonic.net'
            ,'healthierlivingyourway.com'
            ,'harvestrevenue.com'
            ,'begalkecpa.com'
            ,'douglaspipelineinc.com'
            ,'customwealthstrategies.com'
            ,'tyner.org'
            ,'parxhhc.xom'
            ,'bartlettgriffin.com'
            ,'municipaldynamics.com'
            ,'wigginstel.com'
            ,'cleancutland.com'
            ,'catholiccluster.com'
            ,'carolinavein.com'
            ,'gotchacoveredllc.com'
            ,'landiscommunities.org'
            ,'woodsholegroup.com'
            ,'portsofnewyork.com'
            ,'mcatservices.com'
            ,'systecon.us'
            ,'omegahomes.com'
            ,'compusite.com'
            ,'adamsswann.com'
            ,'allianceanimal.com'
            ,'optimusparts.com'
            ,'inspirehotels.com'
            ,'bestdealersoftware.com'
            ,'aol.ciom'
            ,'fcminc.com'
            ,'webberandsons.com'
            ,'trilliumteam.com'
            ,'universalautocare.net'
            ,'sbmgt.net'
            ,'tmd.bz'
            ,'railcometalcraft.com'
            ,'tennalum.com'
            ,'professionalglobaletiquette.com'
            ,'abcsuncontrol.com'
            ,'crpnj.com'
            ,'goldenboyfoods.com'
            ,'morenosteel.com'
            ,'cityoflaurie.com'
            ,'bauvi.com'
            ,'vmweightloss.om'
            ,'oxleylawwv.com'
            ,'brightsales.com'
            ,'eesd.net'
            ,'ashbyre.com'
            ,'mkdiamond.com'
            ,'millcityroasters.com'
            ,'dwiproductions.com'
            ,'safetypcs.com'
            ,'buttonworldcorp.com'
            ,'TRUTAXACCOUNTINGSOLUTIONS.COM'
            ,'stateagent.com'
            ,'nbsinc.com'
            ,'boydtek.biz'
            ,'2com.net'
            ,'spectrumentinc.com'
            ,'rockwestcomposites.com'
            ,'edkochenterprises.com'
            ,'FittingTax.com'
            ,'urgentdoc.com'
            ,'iyengarz.com'
            ,'marginproducts.com'
            ,'slip2000.com'
            ,'paxchristi.net'
            ,'estemerwalt.com'
            ,'rmininc.com'
            ,'aaeinc.com'
            ,'aaker.net'
            ,'walkeragency.org'
            ,'ofova.com'
            ,'AllThingsNumbered.com'
            ,'pioneersteel.us'
            ,'warhawks.k12.mo.us'
            ,'azteccom.com'
            ,'fontainecpa.com'
            ,'olympicoutdoorcenter.com'
            ,'yummycolours.com'
            ,'roneycpa.com'
            ,'bethanyjoco.org'
            ,'minsolutions.com'
            ,'bfmalarm.com'
            ,'vriresearch.com'
            ,'cottenandassociates.com'
            ,'salemnh.gov'
            ,'BanksHardwoods.com'
            ,'risaveena.com'
            ,'journeyhomelending.com'
            ,'burnsandsons.com'
            ,'flashcargo.com'
            ,'tripower.net'
            ,'VIAVAINY.COM'
            ,'highland.in.gov'
            ,'freedomsande.com'
            ,'ahpnet.com'
            ,'APPNORTH.NET'
            ,'cptaxgroup.com'
            ,'advantageinsurancechico.com'
            ,'oakhillnursing.net'
            ,'infintech.com'
        )
GROUP BY RIGHT(c.EmailAddress, LEN(c.EmailAddress) - CHARINDEX('@', c.EmailAddress))
ORDER BY EmailCount DESC

感谢您的帮助。谢谢

0 个答案:

没有答案