我有一个查询,其中包含我要显示的正确条件和字段:
SELECT t.business_process_id,
COUNT (tsp.status) AS COUNT,
ROUND (AVG (tsp.end_date - tsp.start_date), 2) * 24 * 60 AS average,
ROUND (MAX (tsp.end_date - tsp.start_date), 2) * 24 * 60 AS MAX,
ROUND (MIN (tsp.end_date - tsp.start_date), 2) * 24 * 60 AS MIN,
ROUND (MEDIAN (tsp.end_date - tsp.start_date), 2) * 24 * 60 AS MEDIAN,
ROUND (STDDEV (tsp.end_date - tsp.start_date), 2) AS std_deviation
FROM transaction_status_period tsp, transaction t
WHERE t.trans_id = tsp.trans_id
AND tsp.status = 'R'
AND tsp.end_date IS NOT NULL
AND tsp.userid NOT IN ('X', 'Y', 'Z', 'A')
AND EXTRACT (DAY FROM tsp.start_date) =
EXTRACT (DAY FROM tsp.end_date)
AND EXTRACT (YEAR FROM tsp.start_date) =
EXTRACT (YEAR FROM tsp.end_date)
AND EXTRACT (MONTH FROM tsp.start_date) =
EXTRACT (MONTH FROM tsp.end_date)
AND EXTRACT (YEAR FROM tsp.start_date) = 2013
AND NOT EXISTS
(SELECT 1
FROM transaction_status_period tsp1
WHERE tsp1.trans_id = tsp.trans_id
AND tsp.userid = tsp1.userid
AND tsp1.status = 'S'
AND tsp1.timestamp < tsp.timestamp)
GROUP BY t.business_process_id
查询计算的平均值是相关数据集的平均值(年份 = 2013)。有没有办法让查询计算 2013 年所有数据的平均值,不包括异常值?即找到(tsp.end_date - tsp.start_date)
2013 年大多数观测值落在哪里的日期差异的平均值?
该percentile_cont
功能会起作用吗?我不熟悉它,但我知道它计算特定列的百分位数。就我而言,我正在寻找 之间的平均日期差异(tsp.end_date - tsp.start_date)
,但大多数数据点的平均值(不包括异常值)。
任何帮助将非常感激。也许我以错误的方式处理这个查询。