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 7735723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:34:20+00:00 2026-06-01T07:34:20+00:00

Thanks for any help in advance, I can’t wrap my SQL skills around this

  • 0

Thanks for any help in advance, I can’t wrap my SQL skills around this one…
I have two tables like this:

Settings

Customerid     ViewerLimit
       1                   50
       2                   50

Distribution

Customerid     ServerIP
       1                 stream3
       1                 stream4
       2                 stream3

I want to calculate the load on each server. A customer divides the load if they have more than one server, so here customer 1 puts a load of 25 on each server. The result I’m trying to get is this:

ServerIP      Load
 stream3         75
 stream4         25

I tried to do a sum function similar to this:

sum(viewerlimit/(count # of servers)) as load group by serverip

But I can’t do a sub query within a sum function. There are many customers and possibly many servers per customer so it will become too complex to do manually. I appreciate any input.

  • 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-06-01T07:34:21+00:00Added an answer on June 1, 2026 at 7:34 am

    Here is uninspired version with count in derived table:

    select serverip, sum (viewerlimit/cast (ServerCount as float)) Load
    from 
    (
      select customerid, count(*) ServerCount from distribution group by customerid
    ) a
    inner join settings
       on a.customerid = settings.customerid
    inner join distribution 
       on settings.customerid = distribution.customerid
    group by serverip
    

    Sql Fiddle to play around

    UPDATE – an attempt at explanation

    Derived tables are used to produce ad-hoc result sets that can be joined to main body of a query. It is placed in from clause and enclosed in parenthesis. You can use anything an ordinary select can use, top, order by, aggregate functions etc. The only thing you cannot use is correlation to a table in main body. Oh, and CTE. Derived table must be aliased.

    In previous sample derived table ‘a’ selects counts of servers by customerid. Main body sees it as a table with CustomerId and ServerCount columns, ready to be used as any column from all listed tables. A join on customerid is performed between settings and ‘a’. As this is 1:1 relation (both tables produce single row given a customerid), no duplication occurs.

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

Sidebar

Related Questions

Hi thanks in advance for any help. I have two images of a coin
I am using c# .net. Thanks in advance for any help. I have searched
Hello all and thanks for any help in advance. I have a ruby on
Still learning WPF....thanks for any help. Is there any way to Refactor this: <ListBox
Hi all thanks for any help in advance. I am writing a phonegap app
Thanks for any help in advance. So, I'm storing songs in a filesystem with
Do any libraries exist with this functionality? Any recommendations would be useful. Thanks.
Would really appreciate some help with this. I have an app which consists of
Can any help, please> Can anyone provide me with the basics of passing (interprocess)
As title Welcome any comment Thanks interdev

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.