oracle sql 请求列定义不明确
oracle sql request column ambiguously defined
我正在使用 oracle 11g 并尝试执行此请求
select code_mod,INTITULE,code_et,nom ,avg(note)
from note,exam,module,etudiant
where note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET
group by code_mod,code_et
order by code_mod;
但是上面写着!
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error on line 6, colunn 19
有什么问题吗?如果我执行这个请求,它会起作用
select *
from note,exam,module,etudiant
where note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET;
您在 code_mod
、INTITULE
、code_et
、nom
列中至少有两个 note
、exam
、module
,etudiant
tables, 并且不带别名.
例如 module
和 exam
table 都包含 code_mod
列,而在 select 列表中你没有显示它的位置来自
这样使用:
select m.code_mod,intitule,et.code_et,nom ,avg(note)
from note n
inner join exam e on ( n.code_ex = e.code_ex )
inner join module m on ( e.code_mod=m.code_mod )
inner join etudiant et on ( et.code_et = n.code_et )
group by m.code_mod,intitule,et.code_et,nom
order by m.code_mod;
并且您应该在 group by
表达式中包含所有列而不包含 grouping functions
.
您在查询中涉及的多个 table 中有同名的列,因此您必须在列前加上正确的 table 名称,例如:
select
EXAM.code_mod, INTITULE, EXAM.code_et, nom, avg(note)
from
note, exam, module, etudiant
where
note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET
group by
EXAMcode_mod, EXAM.code_et, INTITULE, nom
order by
EXAM.code_mod;
我正在使用 oracle 11g 并尝试执行此请求
select code_mod,INTITULE,code_et,nom ,avg(note)
from note,exam,module,etudiant
where note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET
group by code_mod,code_et
order by code_mod;
但是上面写着!
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error on line 6, colunn 19
有什么问题吗?如果我执行这个请求,它会起作用
select *
from note,exam,module,etudiant
where note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET;
您在 code_mod
、INTITULE
、code_et
、nom
列中至少有两个 note
、exam
、module
,etudiant
tables, 并且不带别名.
例如 module
和 exam
table 都包含 code_mod
列,而在 select 列表中你没有显示它的位置来自
这样使用:
select m.code_mod,intitule,et.code_et,nom ,avg(note)
from note n
inner join exam e on ( n.code_ex = e.code_ex )
inner join module m on ( e.code_mod=m.code_mod )
inner join etudiant et on ( et.code_et = n.code_et )
group by m.code_mod,intitule,et.code_et,nom
order by m.code_mod;
并且您应该在 group by
表达式中包含所有列而不包含 grouping functions
.
您在查询中涉及的多个 table 中有同名的列,因此您必须在列前加上正确的 table 名称,例如:
select
EXAM.code_mod, INTITULE, EXAM.code_et, nom, avg(note)
from
note, exam, module, etudiant
where
note.CODE_EX = exam.CODE_EX
and EXAM.CODE_MOD=MODULE.CODE_MOD
and NOTE.CODE_ET = ETUDIANT.CODE_ET
group by
EXAMcode_mod, EXAM.code_et, INTITULE, nom
order by
EXAM.code_mod;