[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 122
  • 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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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