1

我正在使用 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;
4

2 回答 2

2

您在, , ,表中至少有两个code_mod, INTITULE, code_et,nom列,并将它们放在不带别名的位置。noteexammoduleetudiant

例如,tablemoduleexamtable 都包含code_mod列,并且在选择列表中您没有显示它的来源

像这样使用:

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

于 2017-12-07T17:38:11.033 回答
0

您在查询中涉及的多个表中有同名的列,因此您必须在列前加上正确的表名,例如:

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;
于 2017-12-07T17:41:34.013 回答