sql - 使用oracle计算两个日期之间的时间差(以秒为单位)
问题描述
我正在计算 6 到 59 秒之间的总记录总和,但不起作用。
sum(
case trunc((d.start_date-s.end_date)*24*60*60)
when between 6 and 59 then 1
end) as onemin
from employee;
解决方案
您需要在when
关键字之后移动条件:
sum(
case when trunc((d.start_date-s.end_date)*24*60*60) between 6 and 59 then 1 end
) as onemin
您可能还想如下表达条件,避免对每条记录应用函数(这可能更有效):
sum (
case when
d.start_date - s.end_date >= 6 / 24 / 60 / 60
and d.start_date - s.end_date < 60 / 24 / 60 / 60 -- or 1 / 24 / 60
then 1 end
) onemin
推荐阅读
- python - 从父目录(Python 3)导入包时面临的问题
- c++ - QProcess::readAllStandardOutput() 截断结果
- javascript - 在不使用 node.js 的情况下实时更新网页的最佳方法是什么?
- charts - 谷歌散点图不显示 Y 轴标签
- flutter - SEMBAST - 如何从我的数据库中删除特定数组?
- excel - 替换字符串中的所有字符后/包括空格
- python - 如何知道按钮被点击(Qt)?
- python - 在子流程工作时做点什么?
- ffi - 如何使用 FFI::Platypus 从指针引用中获取字符串值?
- html - 隐藏图像后面的输入字段文件