473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help creating a query to count Unique (Distinct) Values

newnewbie
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our system and thinks I am omnipotent now and can extract any data out of it in the form he wants….The truth is, though I know SOME Access, I am not a programmer…and many queries that he wants me to do have a potential of being monstrous towers of queries built upon queries, etc. ( I do not know SQL or VBA)… HELP!

Table Name: 31 Table

Fields:
caseno after_step HistEntryDate HeadEntryDate
1568170 1 08/15/2005 15-Sep-06
1568170 99 09/06/2005 15-Sep-06
1568170 99 09/07/2005 15-Sep-06
1445110 1 09/21/2005 15-Sep-06
1445111 2 09/21/2005 15-Sep-06
1445110 1 09/22/2005 15-Sep-06
1445111 2 09/23/2005 15-Sep-06

End result of a query (with explanation what the code has to do in Bold)

Column 1: TOTAL CLAIMS: COUNT ALL DISTINCT (UNIQUE) VALUES IN caseno. Result (based on the above table extract): 3

Column 2: TOTAL OPEN CLAIMS: COUNT ALL DISTINCT VALUES IN caseno THAT DO NOT HAVE “99” in after_step Result: 3

Column 3: TOTAL CLOSED CLAIMS: COUNT ALL DISTINCT VALUES IN caseno THAT HAVE “99” in after_step
Means that if I have two 1568170 caseno with the same after_step 99 it needs to be counted only once. Result: 1


HELP!

Thank you.

Lena
May 17 '07 #1
1 3487
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our system and thinks I am omnipotent now and can extract any data out of it in the form he wants….The truth is, though I know SOME Access, I am not a programmer…and many queries that he wants me to do have a potential of being monstrous towers of queries built upon queries, etc. ( I do not know SQL or VBA)… HELP!

Table Name: 31 Table

Fields:
caseno after_step HistEntryDate HeadEntryDate
1568170 1 08/15/2005 15-Sep-06
1568170 99 09/06/2005 15-Sep-06
1568170 99 09/07/2005 15-Sep-06
1445110 1 09/21/2005 15-Sep-06
1445111 2 09/21/2005 15-Sep-06
1445110 1 09/22/2005 15-Sep-06
1445111 2 09/23/2005 15-Sep-06

End result of a query (with explanation what the code has to do in Bold)

Column 1: TOTAL CLAIMS: COUNT ALL DISTINCT (UNIQUE) VALUES IN caseno. Result (based on the above table extract): 3

Column 2: TOTAL OPEN CLAIMS: COUNT ALL DISTINCT VALUES IN caseno THAT DO NOT HAVE “99” in after_step Result: 3

Column 3: TOTAL CLOSED CLAIMS: COUNT ALL DISTINCT VALUES IN caseno THAT HAVE “99” in after_step
Means that if I have two 1568170 caseno with the same after_step 99 it needs to be counted only once. Result: 1


HELP!

Thank you.

Lena
As per my understanding to your question, below is the script
Try this out.
select count(col1),count(col2),count(col3)
from(
select distinct caseno col1,
( select distinct caseno from 31_Table where after_step <> 99) Col2,
( select distinct caseno from 31_Table where after_step = 99) Col3,
from 31_Table
)
May 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: J. Hall | last post by:
Guys, Got this query... --------------------------- SELECT TOP 5 Tbl_admin_hotels.HotelName, (SELECT COUNT(Tbl_marketing_history.HotelID) FROM Tbl_marketing_history WHERE...
8
by: DH | last post by:
Say I have a table with two columns that matter to this example, and . And here is an example of what the rows currently look like: , 1,6/27/2001 1,6/27/2001 1,5/31/2001 2,6/27/2001...
9
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked...
7
by: Riley DeWiley | last post by:
I am continually amazed by SQL's ability to humble me .... I have a toy query into a toy database that looks just like this: SELECT . FROM f, fw, w WHERE f.id = fw.fid and fw.wid = w.id and...
3
by: xhenxhe | last post by:
I'm wondering if something like this can be done in mysql... I have two tables I want to pull data from. One table will contain a unique user_id which I could pull out like: select user_id...
0
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
118
by: Chuck Cheeze | last post by:
This might be in the wrong group, but... Here is an example of my data: entry_id cat_id 1 20 2 25 3 30 4 25 5 35
6
by: troy_lee | last post by:
I am trying to count the total number of units for a given part number that have a Priority rating of 1. Based upon some research, this is what I came up with for my query. Access says that I have...
2
by: lenygold via DBMonster.com | last post by:
Hi Everebody: I have a table: CREATE TABLE CROSS_REFERENCE (ROW# INTEGER NOT NULL ,KEY_WORD CHAR(16) NOT NULL ,QUERY_DESCR VARCHAR(330) NOT NULL ,PRIMARY KEY (ROW#,KEY_WORD)); It is a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.