gpt4 book ai didi

mysql - 如何在sql中获取最小和最大日期

转载 作者:行者123 更新时间:2023-11-29 19:12:27 28 4
gpt4 key购买 nike

嗨,我想子结构到最小日期和最大日期之间的字段,这是我的查询:

SELECT Max(km) - MIN(km)
from positions
where deviceid = 2
and cast(devicetime as date) between MIN('2017-03-23') and Max('2017-03-23'))

但它给出了一个错误。PS,数据库中的devicetime是datetime类型,我使用的是mysql错误是:无效的组函数 enter image description here

最佳答案

您不需要将 MINMAX 放在中间:

SELECT Max(km) - MIN(km)
from positions
where deviceid = 2
and cast(devicetime as date) between '2017-03-23 00:00:00' and '2017-03-23 23:59:59'

关于mysql - 如何在sql中获取最小和最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42973224/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com