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

Percentage calculation

Status
Not open for further replies.

GerryGoldberg

Technical User
Apr 12, 2001
55
My query is:

SELECT code,count(*) as total from myFile GROUP BY code ORDER BY count(*)

I would like to add a column to the resulting dataset that shows the each row's percentage of the total. Can I do this in a single query?

Thanks,

Gerry Goldberg
 
use something like
SELECT code, (count(*)/(SELECT count(*) from myFile)) as percentaje from myFile GROUP BY code John Fill
1c.bmp


ivfmd@mail.md
 

Here is another possibility.

SELECT tbl.Code, Count(*) AS RecCnt, [RecCnt]/[TotRecs] AS [Rec%], DCount("*","tbl") AS TotRecs
FROM tbl
GROUP BY tbl.Code; Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top