SQL按日期获取计数 [英] SQL to get count by date

查看:109
本文介绍了SQL按日期获取计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取表中每个日期的行数.现在我正在做:

I would like to get the number of rows in a table for each date. Right now I am doing:

SELECT SUM(COUNT(*)) FROM videos_videoview GROUP BY date

上面的正确语法是什么?

What would be the correct syntax for the above?

此外,日期不是存储为日期,而是存储为日期时间(2012-01-25 10:26:20).我怎么会在这里GROUP BY约会而忽略时间?

In addition, the date is stored not as a date, but as datetime (2012-01-25 10:26:20). How would I GROUP BY date here, ignoring the time?

推荐答案

按照

As per the documentation, the DATE() function truncates a timestamp down to a date.

select DATE(date),count(1)
from videos_videoview
group by DATE(date);

老实说,这是非常非常基本的SQL.请通读您正在使用的任何RDBMS的文档,或获取有关SQL的基础书籍.

Honestly, this is very, very basic SQL. Please read through the documentation of whatever RDBMS you're using or get a basic book on SQL.

文档:请阅读.爱它.使用它.

Documentation: read it. Love it. Use it.

这篇关于SQL按日期获取计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆