Results 1 to 3 of 3
  1. #1
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368

    sql for grouping and counts

    Hey guys, in need of a bit of help.

    I have a table containing enrollments of apartment tenants for a particular service. our account numbers, however, are not for the tenants, but for the building itself. so when a tenant enrolls, we have a field for their unit that we put in with the building's acct number.

    Now, what I need to do is get the count of account numbers to guage how many enrollments in that building. however, i want each unit to only be counted once (they may have created multiple enrollments because one failed, or whatever)

    so basically, a shortened version of the table would be such

    acctNum, EnrollNum, AptNum


    123, asv, 1
    123, aer, 2
    123, set, 3
    123, eth, 3

    i want the count for acctnum 123 to be 3

    note, there will be other acctnums in the table.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    why not use stacked queries?

    Code:
    select distinctrow acctnum, aptnum
    
    from table
    Code:
    select acctnum, count("*") from query
    
    group by acctnum

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I was kind of hoping to do it all in one shot because it would be updating another field with the counts. It just means breaking down my query into a few more. I wanted a cleaner workflow but i guess this looks more impressive anyway. Looks like I'll get to break 40 queries on this. -_-

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

Similar Threads

  1. Replies: 4
    Last Post: 10-01-2010, 12:06 PM
  2. Replies: 23
    Last Post: 06-30-2010, 02:05 PM
  3. Reporting counts in another query...maybe?
    By Geewaagh in forum Queries
    Replies: 7
    Last Post: 06-04-2010, 07:39 PM
  4. Missing Counts that = 0 in query results
    By dandhjohn in forum Queries
    Replies: 1
    Last Post: 01-29-2010, 11:28 AM
  5. Running counts column
    By diane802 in forum Reports
    Replies: 1
    Last Post: 01-14-2010, 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