3
select count("Status") as Total_Count from "dbo" where "Status" = 'Pass' and "StartDateTime" BETWEEN '2020-11-01 15:00:00' AND '2020-11-01 16:00:00' group by "Status" 

enter image description here

How to get data for every 1 hour interval as in the image above? As currently i changing the time interval manualy. I want get the counts from 12am to 12am next day with 1 hour interval.

1 Answer 1

4

demo: db<>fiddle

When you truncate the start time with date_trunc() at the hour part, all times will be normalized to full hours. This can be used as the GROUP BY criterion.

SELECT COUNT(*) FROM t GROUP BY date_trunc('hour', starttime) 

To format the time column as you expect, you can use the to_char() function:

SELECT to_char(date_trunc('hour', starttime), 'HH12:MI:SS AM') || ' - ' || to_char(date_trunc('hour', starttime) + interval '1 hour', 'HH12:MI:SS AM'), COUNT(*) FROM t GROUP BY date_trunc('hour', starttime) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.