Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 737331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:42:32+00:00 2026-05-14T07:42:32+00:00

To make story short, i’m building self-learning banner management system. Users will be able

  • 0

To make story short, i’m building self-learning banner management system. Users will be able to insert these banners to their site when banners will be shown based on sales/impressions ratio.

I have 4 tables

Banners 
bannerID      int
bannerImage   varchar....

SmartBanners
smartBannerID      int
smartBannerArrayID int
bannerID           int
impressionsCount   int
visibility         tinyint (percents)

SmartBannerArrays 
smartBannerArrayID int
userID             int

Statistics
bannerID          int
saleAmountPerDay  decimal...

Each night i need to generate new “visibility” for each SmartBanner based on whole SmartBannerArray that same user has. So i need to get sum of impressions and sales for each bannerID in SmartBannerArray.

All comes to my mind is to use double cursor, one will loop thought SmartBannerArrays get needed values for sum of impressions and sales and then inner loop which will access each SmartBanner and change it’s “visibility” percentage based on
(sales/impressions)/(sumOfSales/sumOfImpressions)*100

Hope you get the picture…

Is there any other way to design better tables or not to use double cursor to avoid server overload ?

MORE INFO
Each sale written to Statistics table , field is updated because i need daily sum per banner rather each sale. User create BannerArray, choose products he would like to promote. Each product he chose is written to Banners table with proper image and other info.
SmartBanners table stores bannerID so as Statistics table, while BannerArray table assigns this group of banners to certain user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:42:33+00:00Added an answer on May 14, 2026 at 7:42 am

    The picture is not so clear. Why cursors at all, what is wrong with this?

    SELECT SUM(saleAmountPerDay)/SUM(impressionsCount) 
    FROM SmartBanners sb        INNER JOIN
         SmartBannerArrays sba  ON sb.smartBannerArrayID = sba.smartBannerArrayID INNER JOIN
         Statistics ss          ON sb.bannerID = ss.bannerID 
    GROUP BY smartBannerArrayID
    

    Which can be used then as subquery to calculate ‘visibility’ directly.

    EDIT2:
    Illustrating the principle (SQL not optimized), why not:

    UPDATE SmartBanners
    SET visibility = 
        ROUND( 100. * 
        (
        SELECT SUM(saleAmountPerDay)/SUM(impressionsCount) 
        FROM SmartBanners sb        INNER JOIN
             Statistics ss          ON sb.bannerID = ss.bannerID 
        WHERE sb.smartBannerID = SmartBAnners.smartBannerID
        ) /
        (
        SELECT SUM(saleAmountPerDay)/SUM(impressionsCount) 
        FROM SmartBanners sb        INNER JOIN
             SmartBannerArrays sba  ON sb.smartBannerArrayID = sba.smartBannerArrayID INNER JOIN
             Statistics ss          ON sb.bannerID = ss.bannerID 
        WHERE sb.smartBannerArrayID = SmartBAnners.smartBannerArrayID
        ) )
    

    if you want to avoid the cursors.

    Also, not to forget – if this data is not going to be updated often (what’s the frequency of the update of the statistics table? I imagine you update it periodically from some logs) AND if you are looking to maximize read performance you might consider triggers.

    EDIT3:
    In MS SQL you can also use OVER clause, just a short example

    SELECT 
           SUM(saleAmountPerDay) OVER(PARTITION BY BannerID) AS 'TotalSalesByBanner',
           SUM(impressionsCount) OVER(PARTITION BY BannerID) AS 'TotalImpressionsByBanner',
           SUM(saleAmountPerDay) OVER(PARTITION BY smartBannerArrayID) AS 'TotalSalesByArray',
           SUM(impressionsCount) OVER(PARTITION BY smartBannerArrayID) AS 'TotalImpressionsByBanner'    
    FROM   
           SmartBanners sb INNER JOIN
           Statistics ss   ON sb.bannerID = ss.bannerID
    GROUP BY
           SmartBannerID
    

    This SQL is not tested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make a long story short... I'm building a web app in which the
To make a short story long, I'm in charge of fixing all these CSS
To make a long story short I have to use processing in a class
I'm going to make a long story short. It's been a while that I
It's hard to describe the whole problem but to make a long story short,
To make a long story short, I have dynamic pages on a website that
To make a long story short, my terminal was not working so a forum
To make a long story short, it looks as if I am going to
To make a long story as short as possible (ignore this paragraph if you
make is not only useful for building your programming project, but it seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.