2

How can i get the minutes distinct value with timestamp ... Like , if table contains 1 minute 100 records are there...so i want count of records present or not per minute ... For example,

SELECT DISTINCT(timestamp) FROM customers WHERE DATE(timestamp) = CURRENT_DATE

Result should be ..like

timestamp         record
30-12-2019 11:30  5
30-12-2019 11:31  8

2 Answers 2

3

One option would be ::date conversion for timestamp column including GROUP BY :

SELECT timestamp, count(*)
  FROM tab
 WHERE timestamp::date = current_date
GROUP BY timestamp 

Demo for current day

timestamp::date might be replaced with date(timestamp) like in your case.

Update : If the table contains data with precision upto microseconds, then

SELECT to_char(timestamp,'YYYY-MM-DD HH24:MI'), count(*)
  FROM tab
 WHERE date(timestamp) = current_date
 GROUP BY to_char(timestamp,'YYYY-MM-DD HH24:MI')

might be considered.

Sign up to request clarification or add additional context in comments.

2 Comments

Using GROUP BY timestamp might not be what's wanted as timestamp has high resolution (e.g. microseconds).
yes, you're right for the option including microseconds precision @karmakaze , but no problem exists for the data in OP's case.
1

Try something like the following:

SELECT DATE_TRUNC('minute', timestamp) as timestamp, COUNT(*) as record
FROM customers
WHERE DATE(timestamp) = CURRENT_DATE
GROUP BY DATE_TRUNC('minute', timestamp)
ORDER BY DATE_TRUNC('minute', timestamp)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.