Complex select query question for hardcore SQL designers
        Posted  
        
            by eugeneK
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by eugeneK
        
        
        
        Published on 2010-06-14T15:22:04Z
        Indexed on 
            2010/06/14
            16:02 UTC
        
        
        Read the original article
        Hit count: 343
        
Very complex query been trying to construct it for few days with more real success.
I'm using SQL-SERVER 2005 Standard
What i need is : 5 CampaignVariants from Campaigns whereas 2 are with the largest PPU number set and 3 are random.
Next condition is that CampaignDailyBudget and CampaignTotalBudget are below what is set in Campaign ( calculation is number of clicks in Visitors table connected to Campaigns via CampaignVariants on which users click)
Next condition CampaignLanguage, CampaignCategory, CampaignRegion and CampaignCountry must be the ones i send to this select with (languageID,categoryID,regionID and countryID).
Next condition is that IP address i send to this select statement won't be in IPs list for current Campaign ( i delete inactive for 24 hours IPs ).
In other words it gets 5 CampaignVariants for user that enters the site, when i take from user PublisherRegionUID,IP,Language,Country and Region
© Stack Overflow or respective owner