Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Percentage query. 1

Status
Not open for further replies.

Aximboy

Technical User
Aug 3, 2003
63
US


How do you get a percentage of an item compare to another item on the same table?

Example: I have a table of pizza ingredients with ingredients and gallon fields.

        Ingredients    Gallon

        cheese             10

        pizza sauce     25

        mushroom        5

How can I query the percentage of cheese from pizza sauce? Answer should be Cheese 40%.
 


Hi,

Well 10/25 is .4

But what question are you trying to answer?

One question might be, what is the percentage of cheese in the total ingredients, and that would be 10/(10+25+5) or .25

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks for your reply.

The question is, what percent is the total gallon of cheese compare to the total gallon of pizza sauce?
 
Weird question but try:
Code:
SELECT Sum(Abs([Ingredient]="cheese")*[Gallons])/Sum(Abs([Ingredient]="Pizza Sauce")*[Gallons]) AS Expr1
FROM tblPizzaIngredients;

Duane
Hook'D on Access
MS Access MVP
 
Thank you for replying, but it is giving me error that says "This expression is typed incorrectly or it is too complex to be evaluated.
 
@dhookom, my bad! I tried it again before posting my SQL query and IT WORKED!!! Thank you so much!!!

I don't know what happened earlier, it's giving me an error message. I might have done something different.

Again, thanks a million!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top