Solved

Distinct Count in Access....

Posted on 2008-06-24
8
770 Views
Last Modified: 2013-11-28
I understand that there is no "Distinct Count" in Access and I can read and understand the logic of most things, but I am not that DB savvy and have been trying to get substrings to work or something to work, but can figure it out.

Here is a sample Table (called Data):

AuditID          SevCode             IP
-----------------------------------------------
10                  Cat I                    x.x.x.12
10                  Cat I                    x.x.x.35
10                  Cat I                    x.x.x.109
10                  Cat I                    x.x.x.198
2109              Cat II                    x.x.x.12
2109              Cat II                    x.x.x.49
2109              Cat II                    x.x.x.124
2109              Cat II                    x.x.x.93
493                Cat III                    x.x.x.35
493                Cat III                    x.x.x.49
493                Cat III                    x.x.x.143
679                Cat I                     x.x.x.93
679                Cat I                     x.x.x.143
4317              Cat III                    x.x.x.93
4317              Cat III                    x.x.x.104

I am trying to count the total number of Cat I's, II's and III's. The code I am using is either counting total distinct records based off of AuditID (this case = 5) or only shows me the the total of one of the Cat's but doesn't distinct them (this case = 6 Cat I).

What I would like to get spit out is:
Cat I   = 2
Cat II  = 1
Cat III = 2

Any ideas?

Thanks in advance!!!
0
Comment
Question by:SMBowen
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 21859115
A distinct count would just give you the result three, as there are three different SevCode values. What you want to do is to group on the SevCode field, and use count to get the number of records in each group:

select SevCode, count(*)
from Data
group by SevCode
order by SevCode
0
 
LVL 1

Author Comment

by:SMBowen
ID: 21859214
@GreenGhost

That gives me an output of:
Cat I = 6
Cat II = 4
Cat III = 5

It counts the total records of each Cat, I would like to know how many distinct AuditID's there are and then break it down by how many of thoses are Cat I's, II's and III's and output that as the final number.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21859506
select SevCode, count(AuditID & SevCode) from Data group by SevCode order by SevCode
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21859518
Select SevCode, count(AuditID & SevCode) As ID_SevCoe From Data Group by SevCode Order by SevCode
0
 
LVL 1

Author Comment

by:SMBowen
ID: 21859571
@eghtebas

Same thing, it gives me the total records with Cat I's, II's and III's
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 100 total points
ID: 21859704
I see. I think that you have to group it twice to get that result.

I can't check the syntax in Access, as I don't have it installed at the moment, but these give the correct result in SQL Server:

select SevCode, count(*)
from (
	select SevCode
	from Data
	group by AuditId, SevCode
) x
group by SevCode
 
or:
 
select SevCode, count(*)
from (
	select distinct AuditId, SevCode
	from Data
) x
group by SevCode

Open in new window

0
 
LVL 1

Author Closing Comment

by:SMBowen
ID: 31470303
Excellent!!!!!! thank you so much!!! They both worked!!!!
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21860879
sorry... I guess this one should work if you care to try. I know the question is already closed with a good answer from GreenGhost.

Select SevCode, count(AuditID & SevCode) As ID_SevCoe From Data Group by AuditID & SevCode Order by SevCode
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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