Results 1 to 2 of 2
  1. #1
    hiasen83 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    1

    Comparing within group by

    i am completely new to sql , and i`m self teaching so please pardon my ignorance.

    I have a table like

    name1 group1 value1
    name2 group1 value1
    name1 group2 value1
    name2 group2 value2
    name3 group2 value1



    if the values in the 3rd col are consistent within a group i want to output the first row, if they are inconsistent within the same group , i want to output the first row with a value that says 'missing'

    So my output will look like



    name1 group1 value1
    name1 group2 missing


    How do I compare values within the same group? thanks for helping.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Not easy. Consider:

    Query1
    SELECT First(Table1.Field1) AS F1, Table1.Field2, Table1.Field3
    FROM Table1
    GROUP BY Table1.Field2, Table1.Field3;

    Query2
    SELECT First(Query1.F1) AS F1A, Query1.Field2, First(Query1.Field3) AS F3A, Count(Query1.Field3) AS CountF3
    FROM Query1
    GROUP BY Query1.Field2;

    Query3
    SELECT Query2.F1A, Query2.Field2, IIf([CountF3]>1,"missing",[F3A]) AS Data FROM Query2;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2013, 02:34 PM
  2. Replies: 0
    Last Post: 02-25-2013, 04:43 PM
  3. Replies: 2
    Last Post: 06-21-2012, 07:40 PM
  4. Group title carrying forward to next group
    By Amandasr12 in forum Reports
    Replies: 3
    Last Post: 06-06-2012, 02:13 PM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums