Solved

showing percentage in the result table

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now