使用 group by 聚合 sql 中的日期时间
以下是 SQL 可用的聚合函数
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
我需要在日期时间字段上应用聚合函数?它没有在那里列出。 Max()、Min() 不起作用。我需要的是
- 返回最晚日期
- 返回最早日期
是否可能。我可以以某种方式实现它吗?
The following are available aggregate functions for SQL
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
I need to apply aggregate function on datetime field? It is not listed there. Max(), Min() will not work. What I would need is either
- return the latest date
- return the earliest date
Is it possible. Can I implement it somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
min() 和 max() 可以很好地处理日期,
您也可以执行
最新
最早的
BTW SQL Server 没有first() 和last() 函数
min() and max() work fine with dates
you can also do
latest
earliest
BTW SQL Server does not have the first() and last() functions
当然,
MIN
和MAX
有效。.将返回
但是,并非所有聚合都有效。
SUM
、AVG
不起作用,您将收到消息:Of course the
MIN
andMAX
works..will return
However, not all aggregations work.
SUM
,AVG
do not work and you will get the message:是的,我们可以,如果日期作为表的列存在,就像我们有一个表
tbldate
,其中包含名为Datecolmn
的列。然后使用 sql 查询来获取此列的最大值
,它会为您提供此表中存在的
最大日期
......Yes we can, if the date is present as column of the table, Like we have one table
tbldate
which contain Column having nameDatecolmn
.then use the sql query to get the max value of this column Like
and it gives you the
max date
which is present in this table.....