我在这里有几列从其他日期/时间列中获取我们选择不在此查询中显示的数据。我想做两件事。
我想要列SignerAcctID&当SignerAcctID& amp;时,DictatorAcctID对具有分钟的列中的行进行平均/中值。 DictatorAcctID在每一行中重复。因此,如果SignerAcctID = 3且DictatorAcctID = 4并且他们在第1行和第2行执行相同的操作。取第1行和第2行的平均值/中位数。
每次DictatorAcctID = NULL所有列的平均值/中位数(分钟)。我想对我来说困难的部分是我想要平均的列不是来自1个表。他们从其他2个表中的列中获得结果。
SELECT
[Report].SignerAcctID,
[Report].DictatorAcctID,
DATEDIFF(MINUTE, [Order].CreateDate, [Order].CompleteDate) AS 'Ordered To Complete',
DATEDIFF(MINUTE, [Order].CompleteDate, [Report].CreateDate) AS 'Complete to Start Dictate',
DATEDIFF(MINUTE, [Report].CreateDate, [Report].LastPrelimDate) AS 'Start Dictate to Approved',
DATEDIFF(MINUTE, [Report].LastPrelimDate, [Report].LastModifiedDate) AS 'Approved to Signed',
DATEDIFF(MINUTE, [Order].CompleteDate, [Report].LastModifiedDate) AS 'Complete to Signed',
DATEDIFF(MINUTE, [Order].CreateDate, [Report].LastModifiedDate) AS 'Ordered to Signed'
FROM
[Order], [Report]
WHERE
[Order].ReportID = [Report].ReportID
AND
[Order].CompleteDate BETWEEN '2013-02-01 8:00AM' AND '2013-02-01 8:05AM'
;