Oracle如何总计来自不同表的两个选择语句

时间:2018-07-10 04:02:16

标签: oracle sum union

我有这2条选择语句,我正在使用best.ANN.f <- neuralnet(total_let_area ~ income + pop + prop_unemp + medianage + prop_bdegree + prop_vehicle, data = train, hidden = 18, threshold =0.01, act.fct = "tanh", stepmax = 1e+07) best.ANN.pred.f <- compute(best.ANN.f, test[,c("income", "pop", "prop_unemp", "medianage", "prop_bdegree", prop_vehicle")]) head(best.ANN.pred.f$net.result)

union

结果是:

select 'XYZ' as softfield,
  count(form_ref) as asset
from risk_register
where risk_category in ('fdbb8c65-cb78-4e9b-bfb7-d96a9d0b01b1',
                        '42a476db-0b3d-4375-9eba-5051d3a2507e')
and system_type = 'AR'
UNION 
select 'ABC' as softfield,
count(asset_no) from assets where status = 'A' and plant_type not like 'CST%'

我现在要做什么,我需要将两个select语句加起来,像这样:

Softfield Asset
========= =====
ABC       7763
XYZ       146

1 个答案:

答案 0 :(得分:0)

我尝试这个。它的工作。

 select 'XYZ' as softfield,
      count(form_ref) as asset
    from risk_register
    where risk_category in ('fdbb8c65-cb78-4e9b-bfb7-d96a9d0b01b1',
                            '42a476db-0b3d-4375-9eba-5051d3a2507e')
    and system_type = 'AR'

    UNION ALL

    select 'ABC' as softfield,
    count(asset_no) as asset from assets where status = 'A' and plant_type not like 'CST%'

    UNION ALL

    select 'Total' as Softfield,
    sum(asset)
    from
    ( select 'XYZ' as softfield,
      count(form_ref) as asset
    from risk_register
    where risk_category in ('fdbb8c65-cb78-4e9b-bfb7-d96a9d0b01b1',
                            '42a476db-0b3d-4375-9eba-5051d3a2507e')
    and system_type = 'AR'
    UNION ALL
    select 'ABC' as softfield,
    count(asset_no) as asset from assets where status = 'A' and plant_type not like 'CST%')