• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

SQL Select - AVG

I need to know how to average multiple columns in SQL Select.  There 3 columns in the table and I want to compute two averages.  Average 1 would be average of the Base Model Nbr and Image NBR and Average 2 would be the average of the Base Model Nbr, Image Nbr and New Features Nbr.

My Table:

Supplier ID     Base Model Nbr    Image Nbr  New Features Nbr
100                                   0.04                      0.03                  0.03                    
1002                           0.09                      1.00                  0.00
1006                           0.50                      0.50            1.00
10082                           1.00                      1.00                 1.00

I need two additional columns to compute these averages so the output would look like this:

Supplier ID     Base Model Nbr    Image Nbr  New Features Nbr  Average 1    Average 2
100                                   0.04                      0.03                  0.03                           .035          .0335
1002                           0.09                      1.00                  0.00                          .545           .0363
1006                           0.50                      0.50            1.00                           0.5             0.666
10082                           1.00                      1.00                 1.00                                1             1
0
tmajor99
Asked:
tmajor99
  • 2
1 Solution
 
Shaun KlineLead Software EngineerCommented:
If you do not need to compute the average across rows, this simple query should work:
SELECT SupplierID, [Base Model Nbr], [Image Nbr], [New Features Nbr],
    ([Base Model Nbr] + [Image Nbr]) / 2.00 [Average 1], 
    ([Base Model Nbr] + [Image Nbr] + [New Features Nbr]) / 3.00 [Average 2]
FROM <your table>

Open in new window

0
 
YZlatCommented:
try

SELECT SupplierID, BaseModelNbr, ImageNbr, NewFeaturesNbr, (BaseModelNbr + ImageNbr)/2 As Average1, (BaseModelNbr + ImageNbr + NewFeaturesNbr)/3 As Average2
FROM MyTable

Open in new window

0
 
YZlatCommented:
Shaune Kline beat me to it:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now