简体   繁体   English

如何计算工具保持暂停的平均时间? oracle sql 开发人员

[英]How to calculate the avg time a tool stays on hold? oracle sql developer

Im trying to calculate the average time a tool stays on loan.我试图计算工具的平均借出时间。 The time a tool stays on loan is the number of days between loan_status_change_date and tool_out_date (table columns).工具的借出时间是loan_status_change_date 和tool_out_date(表列)之间的天数。 the date type of these 2 columns is ex: 01-SEP-17 whats the best way to approach this?这 2 列的日期类型是例如:01-SEP-17 解决此问题的最佳方法是什么?

We can do arithmetic with Oracle dates.我们可以对 Oracle 日期进行算术运算。 It's not clear from the column names which one is the start of the loan and which the end;从列名中并不清楚哪一个是贷款的开始,哪一个是贷款的结束; in the following example I've assumed loan_status_change is when the tool is returned.在下面的示例中,我假设loan_status_change是返回工具的时间。

select tool
     , avg(loan_status_change - tool_out_date) as avg_loan_days
from   your_table
group by tool
/

The AVG() function is an aggregate function, so it handles the /ns for us. AVG() 函数是一个聚合函数,因此它为我们处理/ns The substraction is to calculate the length of a particular loan, which is the value you want to average.减法是计算特定贷款的长度,这是您要取平均值的值。 The result of that substraction already is a number of days, so no further transformation is necessary.减法的结果已经是几天了,所以不需要进一步的转换。 If your columns have a time element then the result might not be an integer.如果您的列具有时间元素,则结果可能不是整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM