Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIQUE WORK UNIT TOTALS 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
I have the following SQL in a Total Query that shows me the total Faults by category and also gives me a total number of Work Units. Currently there are Five Faults and it also shows me there are Five Work Units. In reality there are only Three unique Work Units even though there are Five Faults. How can I modify the code below to give the Total of Unique Work Units instead of counting each Work Unit for each Fault?

Code:
Select FaultCategory, Count(*) As [Faults/NoFaults]
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]
Group By FaultCategory

UNION ALL Select  'Total Work Units', Count(*)
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt];
 
have you tried

count(DISTINCT [work units field name])

in the second part of your union query?

I think this would achieve the desired result.

Hope it helps,

Alex

A wise man once said
"The only thing normal about database guys is their tables".
 
Thank you!

How and where would that fit into my current SQL?
 
Oh wait, just realized that will only work with ANSI syntax enabled in a newer version of Access. I think you will need a subquery in your second part. Something like this:


Code:
UNION ALL Select 'Total Work Units', count([WorkUnits]) from (select distinct [Work Units Field] from WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt])

Hope it helps,

Alex


A wise man once said
"The only thing normal about database guys is their tables".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top