stanl
07-17-2014, 10:04 AM
I have an Access table with Date, Name, Stuff - which now has over 40,000 rows across several weeks with multiple names. The Stuff column holds either a positive/0 or negative number.
I can query SELECT Date, Name, Count(Stuff) as [Good Stuff] WHERE Stuff>=0 GROUP BY Date,Name
and SELECT Date, Name, Count(Stuff) as [Bad Stuff] WHERE Stuff<0 GROUP BY Date,Name
But I want to combine them as a single query to display Date,Name,[Good Stuff],[Bad Stuff]
Doesn't seem to want to play well with UNION, groups every thing into [Good Stuff]. I tried a subselect and keep getting "Must include WHERE EXISTS in Query" message. If I can get it to a single row I want to expand to an inner join with the Name column and another table to add more columns.
I'll admit, I've been away from more advanced SQL for a while and a bit rusty, so would appreciate some pointers.
I can query SELECT Date, Name, Count(Stuff) as [Good Stuff] WHERE Stuff>=0 GROUP BY Date,Name
and SELECT Date, Name, Count(Stuff) as [Bad Stuff] WHERE Stuff<0 GROUP BY Date,Name
But I want to combine them as a single query to display Date,Name,[Good Stuff],[Bad Stuff]
Doesn't seem to want to play well with UNION, groups every thing into [Good Stuff]. I tried a subselect and keep getting "Must include WHERE EXISTS in Query" message. If I can get it to a single row I want to expand to an inner join with the Name column and another table to add more columns.
I'll admit, I've been away from more advanced SQL for a while and a bit rusty, so would appreciate some pointers.