我有一张这样的表
CREATE TABLE news
(
Id INT NOT NULL auto_increment,
Headline VARCHAR (255) NULL,
InDateTime DATETIME NULL
)
如何获取每秒记录数(InDateTime)?
我正在使用Mysql
样本记录:
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'
预期产出:
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
答案 0 :(得分:9)
让你厌倦了:
SELECT COUNT(id), InDateTime
FROM news
GROUP BY InDateTime
答案 1 :(得分:2)
您希望根据time
对结果进行分组。
对于每个time
,您需要行数。
所以你可以使用这个查询。
select time, count(*)
from news
group by time
此处group by time
将创建单独的不同time
值组。
select time
将在第一列中选择时间。
count(*)
将给出包含该值的行数。
你读得更好this
答案 2 :(得分:1)
任何转化的最简单方法
SELECT `time`, COUNT(*) totalCount
FROM tableName
GROUP by `time
答案 3 :(得分: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