Solved

showing percentage in the result table

Posted on 2006-07-17
4
234 Views
Last Modified: 2008-03-17
I wrote a sql statement in MS Access. the code is:

SELECT col1 as latency, count(col1) as repeat
FROM table1
group by col1
having (count(col1))>1
order by count(col1) desc

and result table is like

latency      repeat
1469      156
1453      154
1484      105
1468      85
1485      66
1500      66
1515      23

is it possible to have percentage in the 3rd column to decribe the percentage of 2nd column (repeat column). the result table looks like below

latency      repeat pct
1469      156   0.xx
1453      154    0.xx
1484      105    0.xx
1468      85      and so on
1485      66
1500      66
1515      23
0
Comment
Question by:rmtogether
  • 2
4 Comments
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 150 total points
ID: 17127820
Select q.latency, q.repeat, (q.repeat / (select count(*) as cnt from table1 as t2)) as percentage_repeat
from
(
SELECT t1.col1 as latency, count(t1.col1) as repeat
FROM table1 as t1
group by t1.col1
having (count(t1.col1))>1
order by count(t1.col1) desc
) as q

Should give you a percentage that each repeat is of the whole volume - you just then need to format it (either in the query or report)
0
 
LVL 3

Expert Comment

by:cdemir
ID: 17128453
hi,
in additioan to Raynard7's comment, i think there needs "sum(cnt)" because of "having (count(t1.col1))>1"

Select q.latency, q.repeat, (q.repeat / select sum(cnt) from (select count(*) as cnt from table1 as t2 group by col1 having count(*) > 1 )) as percentage_repeat
from
(
SELECT t1.col1 as latency, count(t1.col1) as repeat
FROM table1 as t1
group by t1.col1
having (count(t1.col1))>1
order by count(t1.col1) desc
) as q

0
 
LVL 3

Accepted Solution

by:
cdemir earned 350 total points
ID: 17128472
ops, missing paranthesis :

SELECT q.latency, q.repeat,
       (q.repeat / (SELECT SUM (cnt)
                      FROM (SELECT   COUNT (*) as cnt
                                FROM table1 as t2
                            GROUP BY col1
                              HAVING COUNT (*) > 1))) as percentage_repeat
  FROM (SELECT   t1.col1 as latency, COUNT (t1.col1) as repeat
            FROM table1 as t1
        GROUP BY t1.col1
          HAVING (COUNT (t1.col1)) > 1
        ORDER BY COUNT (t1.col1) DESC) as q
0
 

Author Comment

by:rmtogether
ID: 17131459

thanks guys!

i think cdemir is right I need  "sum(cnt)".
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question