对于前。 我的问题:
select *
from
(SELECT distinct b.lname||' '||b.fname as "Manager",b.EMPID as "Mgrid"
from EMPLOYEE1) a,
(select lname,fname,empid from EMPLOYEE1) b
where b.EMPID=a.MGRID)
正在抓取
Manager Mgrid
---------------- --------
Farooque Umer 104
Sontireddy Kiran 107
Chopra Bhupendra 103
但我不能写:
select Manager, Mgrid
from
(select distinct b.lname||' '||b.fname as "Manager",b.EMPID as "Mgrid"
from EMPLOYEE1) a,
(select lname,fname,empid
from EMPLOYEE1) b
where b.EMPID=a.MGRID)
错误:
[错误]脚本行:1-1 -------------------------- ORA-00904:“MGRID”:标识符无效
答案 0 :(得分:3)
因为一旦你开始用双引号括起名字,比如“Mgrid”,就会出现区分大小写的情况。所以不要。这样做:
select Manager, Mgrid
from
(select distinct b.lname||' '||b.fname as Manager,b.EMPID as Mgrid
from EMPLOYEE1) a,
(select lname,fname,empid
from EMPLOYEE1) b
where b.EMPID=a.MGRID)
或者如果你真的喜欢区分大小写的名字,你必须这样做:
select "Manager", "Mgrid"
from
(select distinct b.lname||' '||b.fname as "Manager",b.EMPID as "Mgrid"
from EMPLOYEE1) a,
(select lname,fname,empid
from EMPLOYEE1) b
where b.EMPID=a."Mgrid")
答案 1 :(得分:1)
您应该只在顶级选择中应用化妆品字段命名 - 所有其他标识符应保留为有效的Oracle标识符。
select manager as "Manager", mgrid as "Mgrid"
from
(select distinct b.lname||' '||b.fname as manager, b.EMPID as mgrid
from EMPLOYEE1) a,
(select lname,fname,empid
from EMPLOYEE1) b
where b.EMPID=a.MGRID)
答案 2 :(得分:0)
除了引号之外,我认为你的帖子还包含一个比需要多的括号:
select Manager, Mgrid
from
(select distinct b.lname||' '||b.fname as Manager,b.EMPID as Mgrid
from EMPLOYEE1 a,
(select lname,fname,empid
from EMPLOYEE1) b
where b.empid =a.Mgrid)