Senin, 15 Januari 2018

[MS_AccessPros] Multiple Counts in a query

 

I am trying to do multiple  counts in a single query.


I am after the number of folders in a cabinet and the number of documents in a folder.


So far this is what I got.

SELECT tblCabinets.CabinetID, tblCabinets.CabinetName, Count(tblFolders.FolderID) AS CountOfFolderID, Count(tblDocuments.DocumentID) AS CountOfDocumentID
FROM (tblCabinets INNER JOIN tblFolders ON tblCabinets.CabinetID = tblFolders.CabinetID) INNER JOIN tblDocuments ON tblFolders.FolderID = tblDocuments.FolderID
GROUP BY tblCabinets.CabinetID, tblCabinets.CabinetName;



Query1
CabinetID CabinetName CountOfFolderID CountOfDocumentID
1 SRST TERO Compliance Plans 4 4
2 SRST TERO Applicants 3582 3582
3 SRST TERO VENDORS 176 176
4 SRST TERO Equipment 75 75
5 SRST TERO PROJECTS 4 4
6 TERO-Documents 21 21
7 Job Seek Sign In Sheets 7 7
8 Old Crusher 3 3
9 Tero Specification Manual Project 2 2
10 TERO BOARD MEETINGS 6 6
11 Migration Issue 11
11


 THis is basically returning the number of documents in the cabinets and leaving out a subquery somewhere.


Pertinent table information

tblCabinet

  CabinetID

  CabinetName


tblFolder

  FoldersID

  CabinetID

  FolderName


tblDocuments

  DocumentID

  FolderID

  DocumentName


a Cabinet can have multiple Folders

and a Folder can have multiple documents


I am basically trying to return the number of folders in a cabinet and the number of documents in the folders in the cabinet.


Thank you


Art Lorenzini

Sioux Falls, SD


__._,_.___

Posted by: dbalorenzini@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic ()

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar