question

Mortymorth avatar image
Mortymorth asked

How do I return '0' when there are no occurrences from my CASE-statement?

My query looks like this en simplified form:

SELECT CASE

WHEN time BETWEEN 201905010000000 AND 201905312359999

THEN '1905'

WHEN time BETWEEN 201912010000000 AND 201912312359999

THEN '1912'

ELSE 'OtherMonths'

END AS Period,

Count (1) AS NumberOfSomething

FROM database.table

WHERE --conditions--

GROUP BY Period

I would like to have a table returned with occurrences in '1905' (May) and 0 in '1912' (December) as there are no occurrences in December 2019 yet.

case-statementzero
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.