Solved

showing percentage in the result table

Posted on 2006-07-17
4
241 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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