[英]SQL Query Group by Date Time
I've a database table where I store data 3 to 9 times in a minute.我有一个数据库表,我在一分钟内存储 3 到 9 次数据。 I store data with ID , XYZ value and CreateDateTime Value
我用ID 、 XYZ值和CreateDateTime值存储数据
Now, I want to write a script where the return value shows maximum value of XYZ in every Minute.现在,我想编写一个脚本,其中返回值显示每分钟 XYZ 的最大值。
Please help me to write this script.请帮我写这个脚本。
You can do this using row_number()
:您可以使用
row_number()
执行此操作:
select t.*
from (select t.*,
row_number() over (partition by dateadd(minute, datediff(minute, 0, createdatetime), 0)
order by xyz desc
) as seqnum
from t
) t;
Note: This returns the row in each minute with the maximum value.注意:这将返回每分钟中具有最大值的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.