What I want to do is add a COUNT into a query that is joined on several tables, but I only want to count the thing if it meets a specific condition.
I want the count to only count the rows that have a ReceivedDate like so:
COUNT(ReceivedDate = "0000-00-00 00:00:00", plpq.PurchaseOrderID) AS OrdersForPart
Is there any way to achieve this without having to resort to a sub-query?
Assuming you might want to perform some aggregation on the other rows and thus can’t just exclude them entirely in the
WHEREclause.If this isn’t the case the
WHEREclause is of course the best option.