Consulting

Results 1 to 6 of 6

Thread: Obtain Unique Work Units via SQL

  1. #1

    Obtain Unique Work Units via SQL

    Below is the SQL I have for a Query. The results of my query are below the code. Everything works great except for the WorkUnit totals.
    I am getting the total Records for the date range and I really need the Unique workUnits for the date range. For this particular daterange I
    have a total of 197 WorkUnits but in reality there really are only 89 Unique WorkUnits.
    In the example below on one date range I had 0 No Faults and on the other date range I had 7 No Faults.

    Can anyone tell me how to add to this query to get only
    Unique WorkUnits?

    SELECT 'No Faults' AS [Fault Type], Sum(IIf([FaultCategory]='No Faults',1,0)) AS [NoFault Totals], 
    Count (WorkUnitsFaultsMainTBL.WorkUnit) AS [Total Work Units], 
    FormatPercent(Sum(IIf([FaultCategory]='No Faults',1,0))/Count([WorkUnit]),2) AS [Pct NoFaults]
    FROM WorkUnitsFaultsMainTBL
    WHERE (((WorkUnitsFaultsMainTBL.BuildID) In ("E010","C809","F001","C810","F187","A910","M173","M174")) 
    And ((WorkUnitsFaultsMainTBL.TodaysDate) Between Forms!Queries_ReportsFRM!StartDateTxt And Forms!Queries_ReportsFRM!EndDateTxt));

    Fault Type--------NoFault Totals----------Total Work Units
    No Faults-----------------0--------------------------197

    Fault Type--------NoFault Totals----------Total Work Units
    No Faults-----------------7--------------------------197










  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Have you tried adding the word DISTINCT after SELECT? Stan

  3. #3
    Stan,

    Yes I have and I still get the 197 total.

  4. #4
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Instead of counting the Work Units, group by them instead. Then create another query based on this new sub-query, and then count the Work Units.

  5. #5
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location
    Hi,
    Why dont you create a select query that will just group by workunits...and also count them...the GROUP BY operator will create a distinct and unique list.....and also show the respective count for each of the unique workunits....it would be something like this..

    SELECT WorkUnit Count(WorkUnit) AS WorkUnit
    FROM WorkUnitsFaultsMainTBL
    GROUP BY WorkUnit;

    regards,

    asingh

  6. #6
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location
    apologies for missing out on a COMMA:

    SELECT WorkUnit, Count(WorkUnit) AS WorkUnit
    FROM WorkUnitsFaultsMainTBL
    GROUP BY WorkUnit;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •