[英]How do I get a count of events each day with SQL?
I have a table that looks like this: 我有一个看起来像这样的表:
Timestamp Event User
================ ===== =====
1/1/2010 1:00 PM 100 John
1/1/2010 1:00 PM 103 Mark
1/2/2010 2:00 PM 100 John
1/2/2010 2:05 PM 100 Bill
1/2/2010 2:10 PM 103 Frank
I want to write a query that shows the events for each day and a count for those events. 我想编写一个查询,显示每天的事件和这些事件的计数。 Something like:
就像是:
Date Event EventCount
======== ===== ==========
1/1/2010 100 1
1/1/2010 103 1
1/2/2010 100 2
1/2/2010 103 1
The database is SQL Server Compact, so it doesn't support all the features of the full SQL Server. 该数据库是SQL Server Compact,因此它不支持完整SQL Server的所有功能。 The query I have written so far is
我到目前为止所写的查询是
SELECT DATEADD(dd, DATEDIFF(dd, 0, Timestamp), 0) as Date, Event, Count(Event) as EventCount
FROM Log
GROUP BY Timestamp, Event
This almost works, but EventCount is always 1. How can I get SQL Server to return the correct counts? 这几乎可以工作,但EventCount始终为1.如何让SQL Server返回正确的计数? All fields are mandatory.
所有字段都是必填项。
改变你的goup
GROUP BY DATEADD(dd, DATEDIFF(dd, 0, Timestamp), 0), Event
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.