有两个表1)HR_OrderRequest(要考虑的列是HRdate)其他列是HRUID,UID 2)HR_Supplydetails(要考虑的colmn是HRUID)其他列是创建的,UID,UID 通过考虑HR_Supplydetails的日期,我们应该找到发布HRdate所花费的特定UID时间所花费的平均天数。我有一个平均天数的问题
请做到需要。
答案 0 :(得分:0)
因此,步骤将首先获得订单的天数,以便您对这些表格感兴趣:
order (id, date) # this date is the date the order was placed
supply (id, date) # this date is the date the order was filled
这些可能不对,但我认为它们很接近
select avg(days)
from (select (supply.date-order.date) as days
from order join supply on order.id=supply.id)
但不需要子查询,因为它可以写成:
select avg(supply.date-order.date)
from order join supply on order.id=supply.id;
现在将其映射到您的表格:
HR_OrderRequest (HRUID, UID, HRdate)
HR_Supplydetails (HRUID, UID, createddttm)
select avg(HR_OrderRequest.HRdate-HR_Supplydetails.createddttm)
from HR_OrderRequest join HR_Supplydetails on HR_OrderRequest.HRUID=HR_Supplydetails.HRUID
where UID=?
如果你有日期功能使用它们
答案 1 :(得分:0)
你可以做一个约会:
SELECT AVG(DATEDIFF(day, createddttm,HRdate))
然后加入两张桌子。