我有这些查询(oracle),我需要使用结果然后应用AVG,所以它将是AVG((结果* 7)/ 40)
我尝试用括号等包装它,但它不会起作用。
SELECT
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date)))
FROM CHG_INFRASTRUCTURE_CHANGE
WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015'
AND
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date))) < (SELECT
PERCENTILE_DISC(0.95) within group (order by(( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date) )-( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date) )))
FROM CHG_INFRASTRUCTURE_CHANGE WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015')
这是我尝试过的
AVG((SELECT
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date)))
FROM CHG_INFRASTRUCTURE_CHANGE
WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015'
AND
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date))) < (SELECT
PERCENTILE_DISC(0.95) within group (order by(( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date) )-( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date) )))
FROM CHG_INFRASTRUCTURE_CHANGE WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015'))*7)/40)
我收到了SQLSyntaxErrorException ORA-00900
答案 0 :(得分:0)
假设您的原始查询正确运行,这是包装查询的正确方法 -
select (avg(fn_value)*7)/40 FROM (
SELECT
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date))) as fn_value
FROM CHG_INFRASTRUCTURE_CHANGE
WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015'
AND
((fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date))-(fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date))) < (SELECT
PERCENTILE_DISC(0.95) within group (order by(( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date) )-( fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Submit_Date) )))
FROM CHG_INFRASTRUCTURE_CHANGE WHERE fn_adjusted_date(CHG_INFRASTRUCTURE_CHANGE.Completed_Date)
BETWEEN '01-01-2015' AND '31-01-2015'))
注意我接受了原始查询,将其包装在括号中,并从原始查询中选择结果。结果可以通过你喜欢的任何数学运算。