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

Groupings And Percentages

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
Morpheus7
Asked:
Morpheus7
  • 2
  • 2
1 Solution
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
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
 
Morpheus7Author Commented:
Many thanks for your reply. If I convert to REAL, would this give me a more accurate figure?
Thanks
0
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Yes. - Make sure you do the CAST or CONVERT inside the AVG, i.e. AVG(CAST instead of CAST(AVG(
0
 
Morpheus7Author Commented:
Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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