Results 1 to 6 of 6
  1. #1
    fabilewk is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    7

    Exclamation Need help to make a query

    Hi, I'm facing the following problem:
    I have a table (called stats) which has 2 text fields: "user" and "document" (among others). In this table we keep the accesses to certain documents.
    For example:
    user document


    usrA docA
    usrA docA
    usrA docA
    usrA docB
    usrA docC
    usrB docB
    usrB docC
    usrC docA
    usrC docA
    usrC docA

    I need the output to the query to be:

    user accessed docs total
    usrA 3
    usrB 2
    usrC 1

    I need a ranking of users ordered by distinct document accessed amount.
    We need to know who are the users who accessed to more documents.
    As far as I know, MS Access do not accept the COUNT(DISTINCT...) clause.
    Any ideas? I appreciate any help.
    Thanks in advance,

    fabilewk

    P.S. Excuse me for my poor English

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    Your output data sample does not reconcile with the input.

    Should it be like:
    user accessed docs total
    usrA 5
    usrB 2
    usrC 3

    This is a simple GROUP BY query:
    SELECT User, Count(Document) AS CountOfDocument
    FROM Stats
    GROUP BY User;
    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.

  3. #3
    fabilewk is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    7
    Thanks for your interest.
    I need the count of distinct documents. So, If the user usrA read 3 times the same document (docA) the output should display
    usrA 1

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    Understand better now, try:
    SELECT User, Count(User) AS CountOfUser
    FROM (SELECT User, First(Document) AS FirstOfDocument
    FROM Stats
    GROUP BY User, Document) As Query1
    GROUP BY User;
    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.

  5. #5
    fabilewk is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    7

    Solved

    It worked fine.
    Thanks a lot!

  6. #6
    fabilewk is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    7

    Exclamation Need help again with query

    Hello, users need now the query to display just the first 20 users, so I added TOP 20 following the select clause. The problem is that the query is displaying more than 20 records. Do you know why?
    Thanks again!

    SELECT TOP 20 Stats.[userid] AS User, Count(Stats.[userid]) AS Docs
    FROM (SELECT Stats.[userid], First(Stats.[document]) AS FirstOfDocument FROM Stats WHERE GROUP BY Stats.[userid], Stats.[document]) AS Query1
    GROUP BY Stats.[userid]
    ORDER BY Count(Stats.[userid]) DESC;

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

Similar Threads

  1. How to make my query not equal to...
    By katrinanyc926 in forum Queries
    Replies: 3
    Last Post: 12-08-2010, 11:27 AM
  2. Replies: 1
    Last Post: 07-30-2010, 10:28 AM
  3. make-table query
    By 3PS in forum Access
    Replies: 2
    Last Post: 06-28-2010, 12:54 PM
  4. How to make a query Crash?
    By techexpressinc in forum Queries
    Replies: 5
    Last Post: 03-09-2010, 01:05 PM
  5. Make a table query
    By Fiona in forum Access
    Replies: 4
    Last Post: 06-25-2009, 11:24 AM

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