I have the following
WorkflowID FK_UA DateApprobation
----------- -------------------- -----------------------
1 3 NULL
2 1 NULL
3 1 NULL
4 2 2013-05-31 09:22:33.000
What I'm looking to do is to get a bunch of aggregate fields.
I want to get Approbated workflow , Non-Approbated workflow, All Workflows
The way I'm knowing that is if the "DateApprobation" field is null or has a value.
The thing is, I want to be able to group that by "FK_UA" so I don't know how to have 3 aggregate functions (COUNT) with a group by clause.
I'm looking for a query that can achieve that, I've tried a couple of similar case i found and it returned some weird values.
I tried this :
SELECT
FK_UA
,COUNT(WorkflowID) AS TOTAL
,COUNT(CASE when DateApprobation is not null then 1 else 0 end) AS APPROVED
,COUNT(CASE when DateApprobation is null then 1 else 0 end) AS NOT_APPROVED
FROM Workflow
GROUP BY
FK_UA
but it always return the same things for all 3 values!