with data1 as( SELECT wfqyzt,dwdm,ny, count( decode( qdrq, '2023', 1 ) ), count( decode( qdrq, '2022', 1 ) ) , sum( decode( qdrq, '2022', bdje,0 ) ), sum( decode( qdrq, '2023', bdje,0 ) ), sum( decode( qdrq, '2022', skje,0 ) ), sum( decode( qdrq, '2022', skje,0 ) ), sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='1' then bdje else 0 end) as YGFW, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='2' then bdje else 0 end) as YDRH, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='3' then bdje else 0 end) as KQFW, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='4' then bdje else 0 end) as XQJY, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='5' then bdje else 0 end) as YLWS, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='6' then bdje else 0 end) as JMSW, sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB in ('7','8') then bdje else 0 end) as WCSC, sum(case when JFDWLB in ('2') then bdje else 0 end) as FGS, sum(case when JFDWLB in ('1') then bdje else 0 end) as GLJ FROM A_YDSB_ZXFX001 WHERE qdrq IN ( substr( '202306', 0, 4 ) - 1, '2023' ) group by wfqyzt,dwdm,ny ), data2 as( select * from A_YDSB_ZXFX002 ) select * from data1 ,data2 where data1.dwdm=data2.dwdm 报错ORA-00918: column ambiguously defined怎么解决
时间: 2024-01-12 17:03:35 浏览: 114
根据您提供的SQL查询语句和错误提示,看起来是由于两个子查询中的列名存在重复导致的。为了解决这个问题,您可以在查询中为重复的列名添加表别名来消除歧义。以下是修改后的查询语句:
```sql
WITH data1 AS (
SELECT
wfqyzt,
a.dwdm,
ny,
count(decode(qdrq, '2023', 1)),
count(decode(qdrq, '2022', 1)),
sum(decode(qdrq, '2022', bdje, 0)),
sum(decode(qdrq, '2023', bdje, 0)),
sum(decode(qdrq, '2022', skje, 0)),
sum(decode(qdrq, '2022', skje, 0)),
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='1' then bdje else 0 end) as YGFW,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='2' then bdje else 0 end) as YDRH,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='3' then bdje else 0 end) as KQFW,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='4' then bdje else 0 end) as XQJY,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='5' then bdje else 0 end) as YLWS,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB='6' then bdje else 0 end) as JMSW,
sum(case when JFDWLB in ('3','4','5','6') and XTFWYWLB in ('7','8') then bdje else 0 end) as WCSC,
sum(case when JFDWLB in ('2') then bdje else 0 end) as FGS,
sum(case when JFDWLB in ('1') then bdje else 0 end) as GLJ
FROM
A_YDSB_ZXFX001 a
WHERE
qdrq IN (substr('202306', 0, 4) - 1, '2023')
GROUP BY
wfqyzt, a.dwdm, ny
),
data2 AS (
SELECT * FROM A_YDSB_ZXFX002
)
SELECT *
FROM data1, data2
WHERE data1.dwdm = data2.dwdm;
```
请注意,我在查询中为 data1 子查询中的 `dwdm` 列添加了表别名 `a`,以消除与 data2 子查询中的 `dwdm` 列之间的歧义。您也可以根据实际情况进行适当的调整。
如果问题仍然存在,请提供更多的上下文信息,以便我能够更好地帮助您解决问题。
阅读全文