Grouping in a Query? Kind of an Odd Sort Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simulationguy
    New Member
    • Feb 2010
    • 27

    #1

    Grouping in a Query? Kind of an Odd Sort Problem

    I have a table with names and a linked table with start and end dates for activities
    They want a report (which I am exporting to excel) listed by the earliest end date for an activity. I can create a query that lists names alphabetical and then all of the activities for that person by earliest end date. But they also want the list not in alphabetical order but in order of the earliest end date of all activies for that person.
    There are multiple activity records and therefore multiple enddates for each person

    Example Anderson End Dates 2/15/10, 3/12/10, 1/14/10
    Frank End Dates 2/10/20
    Jones End Dates 1/12/10, 4/15/10

    Creates List

    Jones
    1/12/10
    4/15/10

    Anderson
    1/14/10
    2/15/10
    3/12/10

    Frank
    2/10/20

    I'm not sure how to get the names in order of the earliest start in their list of activities.
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Not sure I understand you correctly ... but
    You could prepend the persons name with the min([End Date])

    [code=sql]
    select min([End Date]) & Name as Nme,[End Date]
    From theTable
    Join theOherTable join conditions
    group by Name,[End Date]
    order by Nme
    [/code]

    or perhaps more simply
    [code=sql]
    select min([End Date]) as Dte, Name,[End Date]
    From theTable
    Join theOherTable join conditions
    group by Name,[End Date]
    order by Dte,Nme
    [/code]

    Comment

    Working...