[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Distinct Count in Access....

Posted on 2008-06-24
8
Medium Priority
?
773 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

649 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