[英]Oracle SQL Merge/Join not working (side by side)
谁能解释为什么这没有产生预期的结果?
select a.*, b.Feb22
from (
select
'Wtd Avg FICO' as Metric
,750.5 as Jan22
from dual
union all
select
'Wtd Avg DTI' as Metric
,0.35 as Jan22
from dual
union all
select
'Wtd Avg LTV' as Metric
,0.75 as Jan22
from dual
) a
inner join
select *
from (
select
'Wtd Avg FICO' as Metric
,700.5 as Feb22
from dual
union all
select
'Wtd Avg DTI' as Metric
,0.50 as Feb22
from dual
union all
select
'Wtd Avg LTV' as Metric
,0.25 as Feb22
from dual
) b on a.Metric = b.Metric
期望的结果:
公制 | 1月22日 | 2月22日 |
---|---|---|
Wtd 平均 FICO | 750.5 | 700.5 |
重量平均 DTI | 0.35 | 0.75 |
Wtd 平均 LTV | 0.75 | 0.50 |
JOIN 只在两个表之间有效,你 b 不是一个我 sql 你需要重写它
在此处查看示例 db<>fiddle
select a.*, b.Feb22
from (
select
'Wtd Avg FICO' as Metric
,750.5 as Jan22
from dual
union all
select
'Wtd Avg DTI' as Metric
,0.35 as Jan22
from dual
union all
select
'Wtd Avg LTV' as Metric
,0.75 as Jan22
from dual
) a
inner join
(select *
from (
select
'Wtd Avg FICO' as Metric
,700.5 as Feb22
from dual
union all
select
'Wtd Avg DTI' as Metric
,0.50 as Feb22
from dual
union all
select
'Wtd Avg LTV' as Metric
,0.25 as Feb22
from dual
) b1 ) b on a.Metric = b.Metric
查询未能执行,因为在INNER JOIN
之后没有指定表。
内部联接正在查找格式为INNER JOIN <table_name>
的表,但您使用的是 SELECT 语句。
您可以通过在另一个子查询中嵌套 SELECT 语句来使用内联视图来解决此问题,如示例中所示。
SELECT a.*, b.Feb22
FROM (
SELECT 'Wtd Avg FICO' as Metric
,750.5 as Jan22
FROM dual
UNION ALL
SELECT 'Wtd Avg DTI' as Metric
,0.35 as Jan22
FROM dual
UNION ALL
SELECT 'Wtd Avg LTV' as Metric
,0.75 as Jan22
FROM dual
) a
INNER JOIN (
SELECT *
FROM (
SELECT 'Wtd Avg FICO' as Metric
,700.5 as Feb22
FROM dual
UNION ALL
SELECT 'Wtd Avg DTI' as Metric
,0.50 as Feb22
FROM dual
UNION ALL
SELECT 'Wtd Avg LTV' as Metric
,0.25 as Feb22
FROM dual
) b_subquery
) b
ON a.Metric = b.Metric
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.