Choose maximum number of seconds

I have a table like this

CREATE TABLE news
(
Id         INT NOT NULL auto_increment,
Headline   VARCHAR (255) NULL,
InDateTime   DATETIME NULL
)

How to get the number of records per second (InDateTime)?

I use Mysql


Examples of entries:

578921,   'headline1', '8/20/2012 12:01:53 PM' 
578922,   'headline2', '8/20/2012 12:01:53 PM' 
578923,   'headline3', '8/20/2012 12:01:53 PM' 
578924,   'headline4', '8/20/2012 12:01:59 PM' 
578925,   'headline5', '8/20/2012 12:01:59 PM' 
578926,   'headline6', '8/20/2012 12:01:59 PM' 
578927,   'headline7', '8/20/2012 12:01:59 PM' 
578928,   'headline8', '8/20/2012 12:02:03 PM' 

Expected Result:

time,                    count
'8/20/2012 12:01:53 PM', 3
'8/20/2012 12:01:59 PM', 4
'8/20/2012 12:02:03 PM', 1 
+5
source share
4 answers

Bore it:

SELECT COUNT(id), InDateTime
FROM news
GROUP BY InDateTime
+9
source

Here you want to group your result according to time. For each timeyou need the number of rows. So you can use this query.

select time, count(*)
from news
group by time

This group by timewill create a separate group of different values time. select timewill select the time in the first column. And it count(*)will give the number of lines containing this value.

Better you read this

+2
source

SELECT `time`, COUNT(*) totalCount
FROM tableName
GROUP by `time
+1
SELECT InDateTime AS Time, COUNT(InDateTime) AS Count
FROM NEWS
GROUP BY InDateTime

Time                     Count
2012-08-20 12:01:53.000   3
2012-08-20 12:01:59.000   4
2012-08-20 12:02:03.000   1
+1

All Articles