CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Query Help!!

  1. #1
    Join Date
    Nov 2003
    Location
    San Diego, California
    Posts
    49

    Query Help!!

    Hello,

    I am using CR 9 with an access database and I am trying to create a report by writing a command statement to retrieve the data. I've been fighting with this one all day and can't get it.

    I have three tables that I'm trying to join together. I've never had any problem when I'm joining two tables but with three I can't get it.

    I have a Group, Hour and Detail table.

    The Group Table consists of the Group field and the Member field. The Hour table simply has one record for each hour of the day. So there are 24 records. I use it just so I can show every hour of the day in my reports. The Detail table has all of the activity that I need to report on.

    My report needs to have three groups: Group, Member, Hour of Day. I then need to show a count of activity by Hour.

    Group 1
    Member 1
    00:00 : 100
    01:00 : 75
    ....
    23:00 : 20
    Member 2
    etc...

    The following SQL statement works but it only returns an hour group for hours that actually have data on the Detail table:

    HTML Code:
    Select Group.GroupNumber, Group.MemberNumber, Hour(Detail.StartingTime), Count(Detail.ReferenceNumber)
    
    From Group left join Detail On Group.MemberNumber = Detail.MemberNumber
    
    Group By Group.GroupNumber, Group.MemberNumber, hour(Detail.StartingTime)
    Is there a way I can incoroporate another join into that statement so I can also bring back all of the Hours from the Hours table?

    If I could incorporate this into my sql as well I think I would be in good shape. I'm just not sure how do do it...

    Code:
    Select Hour.Hour 
    
    From Hour Left Join Detail On Hour.Hour = Detail.StartingTime
    Hopefully this makes sense. I sincerely appreciate your help with this!

    Stephanie

  2. #2
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651

    Re: Query Help!!

    Try this:
    Code:
    SELECT Group.GroupNumber, Group.MemberNumber, HOUR(Detail.StartingTime), COUNT(Detail.ReferenceNumber)
    FROM Group 
    LEFT JOIN Detail On Group.MemberNumber = Detail.MemberNumber
    LEFT JOIN On Hour.Hour = HOUR(Detail.StartingTime)
    GROUP BY Group.GroupNumber, Group.MemberNumber, HOUR(Detail.StartingTime)
    I'd rather be wakeboarding...

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured