question

Mortymorth avatar image
Mortymorth asked

How do I count different ocurrences?

I tried following so many different examples but nothing seems to work.

I would like to count occurences within different periods of time.

I have a column with timestamps: e.g. 201308241158105

I would like to count all occurences in e.g. august 2013, september 2013, etc. so that I get an output of numbers of occurences for each month.

I imagine something looking like this example:

select
	count(case when timestamp between 201308010000000 and 201308310000000 then 1 end) as August,
   	count(case when timestamp between 201309010000000 and 201309300000000 then 1 end) as September 
from WHATEVERDATABASE
countcase-statement
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.

1 Answer

· Write an Answer
ThomasRushton avatar image
ThomasRushton answered

Try SELECT SUM(CASE...Then 1 ELSE 0 END)...

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.

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.