The following is a non-inverse version with an invoice in the view:
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
UPDATE - attempt to explain
Derived tables are used to create custom result sets that can be combined with the main part of the query. It is placed from the sentence and is enclosed in parentheses. You can use everything that ordinary choices, top, order, aggregate functions, etc. can use. The only thing you cannot use is correlation with the table in the main body. Oh, and CTE. The view must be an alias.
In the previous test table "a", the number of servers by customerid is selected. The main body sees it as a table with CustomerId and ServerCount columns, ready for use as any column from all the tables listed. Joining to customerid is done between the settings and "a". Since this ratio is 1: 1 (both tables produce one row, taking into account customerid), duplication does not occur.
Nikola Markovinović
source share