I'm doing a COUNT but cannot get the value 0 when there are no rows in the result.
If I remove the where condition:
AND documentstats.OPENINGDATE >= '2021-01-01T00: 00: 00.000'
it works fine and I get the value 0 when there are no rows in the result.
I am looking for an option to return value 0 in the NumberOfViews column when no rows are found in my count.
Can anyone help me?
SELECT 
    customertodocument.DocId,
    COUNT (documentstats.DocId) AS NumberOfViews
FROM 
    customertodocument 
LEFT JOIN 
    documentstats ON customertodocument.DocId = documentstats.DocId 
                  AND customertodocument.customerId = documentstats.customerId
WHERE 
    customertodocument.customerId = '1111'
    AND documentstats.openingdate >= '2021-01-01T00:00:00.000'
GROUP BY 
    customertodocument.DocId
ORDER BY 
    NumberOfViews ASC
 
     
     
     
    