tsql - Is this the correct way to do a Weighted Avg? -


Field.

  Select eer.Market, eer.KLA, eer.Term, case scdesc When 'ICS' then 'Act' and other. Sddc end as ScDesc, eer.Term such as- Term_Anual, eer.VaMonths, eer.RentPrice, eer.BuyPrice, eer.TransactionID View1 eer from WHERE (@Term = 'Long Term' and Term_Anual> 11)) Or order by eer.market, eer.KLA, eer.ScDesc   

or (@Term = 'Short Term' and Term_Anual & lt; 12)) and (Archive @Archiveed) This is my first attempt to average weighted so that there are some things about which I am not sure about.

So whatever I did, he is trying to connect a CTE together.

  SELECT [base]. Market, [base]. MSA, [Base]. Archaeid, [Base]. Transsexual [Base] SCDC, SM ([Base] .KLA) * [Weighted]. KLA, SM (Vmonthes, SAM ([Base]. Artpris) as KLA / SM ([weighted] .KLA) * [weighted]. Ratedpiece / SUM Rent (rent) as per [[weighted] .rentpris), SM ([Base]. Boopers) * [weighted] .uppris / SUM ([weighted]. BEPRIS) Buy Buy AA View1 [Base] From Inner (select eer. Market, eer.KLA, eer.Term, case scdesc When 'ICS' ends again in 'Act' F.E. Scscc SCDC, e In the form of RAR, ARM, Year Vimes, Year Rterparis, Year, Bypris, Year, Transaction from Wear 2 ER WHERE ((@ term = 'long term' and 'term_one' 11) or (@Term = 'Short term' and Term_Anual & lt; 12) and in the archiveID (@ ArchivedID) as eer.market, eer.KLA, eer.ScDesc [Weighted] as [weighted]  << Apart from this, I do not know where I should welfare in two questions or where I want to take weight.  

Some fields (with SM Are you trying to weight down?

I should hold my hand some time ago because I do not believe that I am convinced that I am doing this right. Areas in fields, money, numerical, etc. are being done. So do not worry that if they are the appropriate field types, the remaining areas [base] are not weighted, I do not want those weighters to choose directly in my external query.

As mentioned in some comments, your question is not particularly clear, but if you have something Values ​​in one table are:

  DECLARE @SampleData TABLE (value decimal (3,2), [weight] DCIML  value  and  weight  (3, 2)) @ Sample selection 6, 3 selection of union, selection of union 1, selection of union 1, union 5, select union 3, 1 union selection 1, 1 selection of union 3, 2 union selection 4, 1   

You average ( Sat) and weighted average can be returned:

  Select AVG (value) AVG (value * [weight]) @ sample data from AS weighted mn    

Comments