Count morethan one column in a table (1 Viewer)

prabhus

Registered User.
Local time
Yesterday, 19:38
Joined
Mar 14, 2012
Messages
67
Dear All,

I have attached a file with Table, Current Result & Desired Result.

I have a table with Month, A, B to G with True or False check box inputs, what i need is on every month, in each category what is the total False;
In the past, i created a count query for each category like A to G and then finally link it. So i want to simplify it and i used below SQL but its giving me the result but not in a good format ( please check current result in my excel file ) how to improve this or is there a better way of doing this, please suggest.

SQL used

SELECT Tbl_DateMonth.[Month], Count(*) AS A, '' as DA_FIEPending, '' as B,'' as DA_PFMEAPending
FROM Tbl_DateMonth LEFT JOIN ([MasterTable_ EngineeringChanges] LEFT JOIN [MHEX Processors Update] ON
FROM Tbl_DateMonth LEFT JOIN ([Table1] LEFT JOIN [Table2] ON [Table1].UniqueID = [Table2].[Unique Id]) ON Tbl_DateMonth.[Effective Month] = [Table1].[Effective Month]
WHERE ((([Table1].DA) Like "-1") AND (([Table2].A) Like "0"))
GROUP BY Tbl_DateMonth.[Month];
UNION ALL
SELECT Tbl_DateMonth.[Month],'' as A, Count(*) AS B,
FROM Tbl_DateMonth LEFT JOIN ([Table1] LEFT JOIN [Table2] ON [Table1].UniqueID = [Table2].[Unique Id]) ON Tbl_DateMonth.[Effective Month] = [Table1].[Effective Month]
WHERE ((([Table1].DA) Like "-1") AND (([Table2].B) Like "0"))
GROUP BY Tbl_DateMonth.[Month];
 

Attachments

  • Book1.xls
    112.5 KB · Views: 75

namliam

The Mailman - AWF VIP
Local time
Today, 04:38
Joined
Aug 11, 2003
Messages
11,695
Your query wont work as is, no sense on working on a product that doesnt work.

If you want to get what you "desire", either you have to join your count queries or work with an "IIF" inside your counts
 

BlueIshDan

☠
Local time
Yesterday, 23:38
Joined
May 15, 2014
Messages
1,122
I agree with namliam.

This query is not structured right and you might as well start over.

Give me your table names and definitions and what it is you would like to see from them and we'll go from there I guess.

Here is your query formatted so that you can see where the mistakes are more easily.
Code:
SELECT 
	Tbl_DateMonth.[Month],
	Count(*) AS A, 
	'' as DA_FIEPending, 
	'' as B,
	'' as DA_PFMEAPending

FROM 
	Tbl_DateMonth 
	LEFT JOIN ([MasterTable_ EngineeringChanges] 
		LEFT JOIN [MHEX Processors Update] ON 
FROM 
	Tbl_DateMonth 
	LEFT JOIN ([Table1] 
		LEFT JOIN [Table2] 
		ON [Table1].UniqueID = [Table2].[Unique Id]) 
	ON Tbl_DateMonth.[Effective Month] = [Table1].[Effective Month]

WHERE 
	((([Table1].DA) Like "-1") 
	AND (([Table2].A) Like "0"))

GROUP BY 
	Tbl_DateMonth.[Month];

UNION ALL

SELECT 
	Tbl_DateMonth.[Month],
	'' as A,
	 Count(*) AS B,
 
FROM 
	Tbl_DateMonth 
	LEFT JOIN ([Table1] 
		LEFT JOIN [Table2] 
		ON [Table1].UniqueID = [Table2].[Unique Id]) 
	ON Tbl_DateMonth.[Effective Month] = [Table1].[Effective Month]

WHERE 
	((([Table1].DA) Like "-1") 
	AND (([Table2].B) Like "0"))

GROUP BY Tbl_DateMonth.[Month];
 

prabhus

Registered User.
Local time
Yesterday, 19:38
Joined
Mar 14, 2012
Messages
67
Thank you,

Here i am attaching the result of my Query and the result i am expecting to display using sql or vba;
 

Attachments

  • Book2.xls
    128 KB · Views: 83

namliam

The Mailman - AWF VIP
Local time
Today, 04:38
Joined
Aug 11, 2003
Messages
11,695
cant you do "simply"
Code:
Select Sum(Iif(A;1;0) ) countofA
, Sum(Iif(b;1;0) ) countofB
, ...
from table2
??
 

Users who are viewing this thread

Top Bottom