Solved

showing percentage in the result table

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server views 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 Access…
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.

760 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

24 Experts available now in Live!

Get 1:1 Help Now