Results 1 to 4 of 4
  1. #1
    shah1419 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    30

    need present and absent student.

    Dear All,


    i have two tables. table-1 contains 3 fields and table 2 contains two fields. i want to get the result in group by class on specific date. please view the attached file.Click image for larger version. 

Name:	Untitled.jpg 
Views:	20 
Size:	115.0 KB 
ID:	30931

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    2 queries:
    present is easy because they attended.

    but absent must be an OUTER join.
    join the class Roster table to the class attend date table
    dbl-click the join line,
    select ALL records in ClassRoster, some records in classAttendDate
    bring down fields: tClassRoster.[id] , and tClassAttendDate.[id]
    under criteria for tClassAttendDate.[id] , set: =null

    this says who was NOT there on that date.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,966
    BTW, Name is a reserved word and should not use reserved words as names for anything. Also, advise no spaces or punctuation/special characters (underscore only exception).

    Userid in Table2 is a FK, not PK.

    Date value includes the time and I see the same date with different times. Need to extract the date part. Regarding use of international date, review http://allenbrowne.com/ser-36.html.

    @ranman, the date field will be Null so there will be no way to know what that absence date is which prevents relating, grouping, and filtering by date. Need a dataset of all possible user and date pairs. This requires a Cartesian relation query of the two tables.

    @shah, your Present and Absent values appear to be in wrong columns.

    Query1: AllUserDate
    SELECT DISTINCT Table1.Userid, Int([Checktime]) AS Dt, Table1.Class FROM Table1, Table2;

    Query2: Table2Adj
    SELECT Table2.Userid, Int([Checktime]) AS Dt, Table1.Class
    FROM Table1 INNER JOIN Table2 ON Table1.Userid = Table2.Userid;

    Query3:
    SELECT AllUserDate.Dt, AllUserDate.Class, Count(AllUserDate.Userid) AS Total, Sum(IIf(Not [Table2Adj].[Dt] Is Null,1,0)) AS Present, Sum(IIf([Table2Adj].[Dt] Is Null,1,0)) AS Absent
    FROM Table2Adj RIGHT JOIN AllUserDate ON (Table2Adj.Dt = AllUserDate.Dt) AND (Table2Adj.Userid = AllUserDate.Userid)
    GROUP BY AllUserDate.Dt, AllUserDate.Class;
    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.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Class" is also a reserved word; should not use reserved words as names for anything.

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

Similar Threads

  1. Replies: 9
    Last Post: 08-08-2017, 11:33 AM
  2. Prevent Warning of Absent Images
    By Nip351 in forum Reports
    Replies: 3
    Last Post: 06-22-2017, 03:27 PM
  3. Replies: 1
    Last Post: 03-09-2015, 12:07 PM
  4. Replies: 2
    Last Post: 07-21-2014, 08:47 AM
  5. Look if value is present
    By JeroenMioch in forum Access
    Replies: 3
    Last Post: 07-02-2012, 06:12 PM

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