?
Solved

SQL Select - AVG

Posted on 2016-09-21
3
Medium Priority
?
65 Views
Last Modified: 2016-09-22
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
Comment
Question by:tmajor99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 41809495
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
 
LVL 35

Expert Comment

by:YZlat
ID: 41809562
try

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

Open in new window

0
 
LVL 35

Expert Comment

by:YZlat
ID: 41809566
Shaune Kline beat me to it:)
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question