Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Groupings And Percentages

Posted on 2014-12-16
4
Medium Priority
?
117 Views
Last Modified: 2014-12-16
Hi,
I have a table containing the following columns:
ProdGroup,   ProductID, PercentFat, PercentProt.

I would like to be able to get the average PercentFat and PercentProt per ProdGroup.
The fields are all of type INT. There are multiple ProductIDs within each ProdGroup.

So to be able to return one row for each ProdGroup, together with the average percentage PercentFat  and PercentProt

Any assistance would be appreciated
Thanks
0
Comment
Question by:Morpheus7
[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
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40502170
Select ProdGroup, AVG(PercentFat) as Avg_PercentFat, AVG(PercentProt) as Avg_PercentProt
From MYTABLE
Group By ProdGroup
Order By ProdGroup

Open in new window


This assumes that you are happy in having the averages as INTs.
0
 

Author Comment

by:Morpheus7
ID: 40502183
Many thanks for your reply. If I convert to REAL, would this give me a more accurate figure?
Thanks
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40502265
Yes. - Make sure you do the CAST or CONVERT inside the AVG, i.e. AVG(CAST instead of CAST(AVG(
0
 

Author Closing Comment

by:Morpheus7
ID: 40502286
Many thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

670 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