vbnetcoder
asked on
SQL Query --- counting by groups
I have a table with data that looks something like this.
Project ID DocumenID
1 1
1 2
1 3
2 4
3 5
3 6
I need to create a sql statement that will give me a count of ALL the documents as well as ammount of documents
per project. Any clue how?
Project ID DocumenID
1 1
1 2
1 3
2 4
3 5
3 6
I need to create a sql statement that will give me a count of ALL the documents as well as ammount of documents
per project. Any clue how?
ASKER
This is the exact query:
SELECT P.[Project Name], Count(DP.Document_ID) AS DocumentCount
FROM [MyTableReports].[dbo].[Do cument_Pro ject] DP
INNER JOIN [MyTableReports].[dbo].[Do cument_Fil es] DF
ON DF.Document_ID = dp.Document_ID
INNER JOIN [MyTableReports].[dbo].Pro ject P
ON P.ID = dp.Project_ID
Group By P.[Project Name]
And it returns this:
Project Name DocumentCount
AA Project 1
BB project 2
CC roject 2
ttttttt 1
I need it to return:
Project Name DocumentCount Total Documents
AA Project 1 5
BB project 2 5
CC roject 2 5
ttttttt 1 5
How?
SELECT P.[Project Name], Count(DP.Document_ID) AS DocumentCount
FROM [MyTableReports].[dbo].[Do
INNER JOIN [MyTableReports].[dbo].[Do
ON DF.Document_ID = dp.Document_ID
INNER JOIN [MyTableReports].[dbo].Pro
ON P.ID = dp.Project_ID
Group By P.[Project Name]
And it returns this:
Project Name DocumentCount
AA Project 1
BB project 2
CC roject 2
ttttttt 1
I need it to return:
Project Name DocumentCount Total Documents
AA Project 1 5
BB project 2 5
CC roject 2 5
ttttttt 1 5
How?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>I need it to return:
Project Name DocumentCount Total Documents
AA Project 1 5
BB project 2 5
CC roject 2 5
ttttttt 1 5 <<
Can you post the data that should return those results with some explanation as to why?
Project Name DocumentCount Total Documents
AA Project 1 5
BB project 2 5
CC roject 2 5
ttttttt 1 5 <<
Can you post the data that should return those results with some explanation as to why?
ASKER
ty
SELECT ProjectID, COUNT(*)
FROM Projects
GROUP BY ProjectID WITH ROLLUP