我正在尝试使用以下查询创建视图。
SELECT the_day, t1, t2
FROM year_days
LEFT JOIN (SELECT tea_prodcution_date, SUM(quantity) t1
FROM TEA_PRODUCTION
WHERE field_name like 'T1'
GROUP BY tea_prodcution_date) ON the_day = tea_prodcution_date
LEFT JOIN (SELECT tea_prodcution_date, SUM(quantity) t2
FROM TEA_PRODUCTION
WHERE field_name like 'T2'
GROUP BY tea_prodcution_date) ON the_day = tea_prodcution_date
ORDER BY the_day
year_days 是使用以下查询创建的视图。
SELECT add_months(TRUNC(sysdate - (365), 'YYYY'),to_number(to_char(sysdate,'mm'))) + (level - 1) AS the_day
FROM dual
CONNECT BY level <=
to_number(TO_CHAR(last_day(add_months(TRUNC(sysdate, 'YYYY'), 11)),
'DDD'))
当我尝试执行我的第一个查询来创建视图时,我得到了以下错误。
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error at Line: 10 Column: 58
ON the_day = tea_prodcution_date
行发生错误。
我怎么能纠正这个错误并创建上面的视图?
答案 0 :(得分:1)
我的查询发现错误。查询应该如下更正。
SELECT the_day, t1, t2
FROM year_days
LEFT JOIN (SELECT tea_prodcution_date, SUM(quantity) t1
FROM TEA_PRODUCTION
WHERE field_name like 'T1'
GROUP BY tea_prodcution_date) aa ON the_day = aa.tea_prodcution_date
LEFT JOIN (SELECT tea_prodcution_date, SUM(quantity) t2
FROM TEA_PRODUCTION
WHERE field_name like 'T2'
GROUP BY tea_prodcution_date) bb ON the_day = bb.tea_prodcution_date
ORDER BY the_day