Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

showing percentage in the result table

Posted on 2006-07-17
4
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 600 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 1400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

688 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