假设我们有一个包含事件和发生日期的表,它看起来像:
+-------------+---------------+
| event_token | date_recorded |
+-------------+---------------+
| event_1 | 06.11.2017 |
+-------------+---------------+
| event_2 | 06.11.2017 |
+-------------+---------------+
| event_3 | 06.11.2017 |
+-------------+---------------+
| event_4 | 06.11.2017 |
+-------------+---------------+
| event_1 | 05.11.2017 |
+-------------+---------------+
| event_7 | 05.11.2017 |
+-------------+---------------+
| event_5 | 04.11.2017 |
+-------------+---------------+
什么是最好的sql(pl sql)语句,它返回每天发生的事件总数。 预期结果应如下所示:
+------------+-------------+
| date | event_count |
+------------+-------------+
| 06.11.2017 | 4 |
+------------+-------------+
| 05.11.2017 | 2 |
+------------+-------------+
| 04.11.2017 | 1 |
+------------+-------------+
答案 0 :(得分:1)
由于您计算每个事件即使重复,您也可以按日期和计数记录进行汇总。
SELECT date_recorded AS date, COUNT(*) AS event_count
FROM your_table
GROUP BY date_recorded;
答案 1 :(得分:0)
如果您按日计算,可以按日期计算并尝试排除时间戳。
SELECT to_char(date_recorded,'yyyy/mm/dd') as date, COUNT(*) as event_count
FROM your_table
group by date_recorded;