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

How do I find get a percentage to work in a query?

Status
Not open for further replies.

Soulbait

MIS
Mar 12, 2003
43
US
I have a table which has 5 fields which I am totaling each field and then the total of all 5 fields within a query

What I would also like is another field that gives me a percentage between the first 2 fields and the total of all 5 fields.

Can this be done, If this makes no sense which I might since I'm half awake and half sick let me know.

Thanks

Soulbait
"Despite the cost of living, it's still quite popular."
 
SELECT sum(field1)[field1sum], sum(field1)/sum(field1+field2)[field1percent], sum(fields)[field2sum],sum(field2)/sum(field1+field2) [field2percent]
FROM myTable Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
OOppss! I think you are looking for somehting more along these lines... Field 5 will hold the percentage that field 1 is when compared to the sum of the fields for that row

update myTable set field5 = field1 / (field1 + field2 + field3 + field4) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Thats kinda what I thought it should look like, but where do i need to be placing the statement. I must not be placing it in the right spot.
 
go to "Queries" and select "CReate Query in design view", select any table, close the table selector and view the SQL, write the query and execute it there. I recommend making a copy of the table before you try the updates, just in case. Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Here's my current SQL Statement for my query

SELECT DISTINCTROW [Card 1].Question, [Card 1].CardType, Sum([Card 1].[Strongly Agree]) AS [Strongly Agree], Sum([Card 1].Agree) AS Agree, Sum([Card 1].Disagree) AS Disagree, Sum([Card 1].[Strongly Disagree]) AS [Strongly Disagree], Sum([Card 1].[No Opinion]) AS [No Opinion], Count(*) AS Total
FROM [Card 1]
GROUP BY [Card 1].Question, [Card 1].CardType, [Card 1].[Date Entered]
HAVING ((([Card 1].[Date Entered]) Between (Date()) And (Date()-30)))
ORDER BY [Card 1].CardType;

I need a 9th field at the end of the query, and that is the one where the percentage comes in.

Here's the Statement you gave me translated so that it agrees with my query I think.

update [Card 1] set field9 = ("Strongly Agree" + "Agree") / "Total"

I probably have this wrong since my head is pounding from trying to get over the flu.

Just curious where I would put your statement into my current statement.

Sorry if I'm sounding confused or something and thanks for the patience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top