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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Im trying to use two fields to give me a percentage in a Sum field,

Status
Not open for further replies.

KaayJaay

IS-IT--Management
Jul 6, 2004
64
US
Im trying to use two fields to give me a percentage in a Sum field, one field is a Count() field and the other is a regular field(total). I am trying to get the percentage using Sum([Count]/[total]), but it keeps saying that i cannot use a subquery, but i didnt think that was a subquery.

Also I am using Microsoft Access.

KaayJaay
 
Here are some ideas.


Code:
SELECT widget, (COUNT(*)/SUM(amount)) AS Percentage
FROM Shipments
GROUP BY widget
This will count the numbers of each widget shipped, add up the amounts of the shipments and display the ratio. In no way is this a percentage but we can call it Percentage if we like.

You may be looking for a percentage as in what percentage of total widgets shipped were Hot Wheels. That percentage requires two queries, one to count the total number over all widgets, a second one to breakdown the count for each widget. The grand total might be obtained by using a subquery. This might work.
Code:
SELECT widget, COUNT(*)/(SELECT COUNT(*) FROM Shipments) AS Percentage
FROM Shipments
GROUP BY widget

Access may have reporting facilities to do this, look into crosstab queries.
 
Thank You very much this is exactly what it is i was looking for.

KaayJaay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top