1

我不明白我得到的错误!

我的问题是我必须显示员工的姓名和他们参加的会议的数量。如果员工没有直接在任何会议上工作,则必须为该员工显示 0。与此查询关联的表是:

Employee_C 表:

 EID  NAME   SALARY          MID
---    -------------------- -----
e01   Wilson    53000
e02   Smith      48000       e01
e03   Jones      38000       e01
e04   Loftus     41000
e05   Fox        54000       e04
e06   Smith      45000       e04
e07   Green     48000
e08   Fox         49000      e04
e09   Wolf       41000       e04
e10   Wang        32000      e01
e11   Phillips   33000       e07
e12   Liu         27000      e07

Deals_C 表:

EID CONFID
---    ------
e02   c00001
e03   c00001
e05   c00001
e06   c00001
e03   c00002
e08   c00002
e09   c00002
e10   c00002
e03   c00003
e05   c00003
e06   c00004
e08   c00005
e09   c00005
e10   c00005
e06   c00005
e11   c00006
e12   c00006
e05   c00007
e06   c00007
e08   c00007
e09   c00008
e10   c00008
e11   c00008
e02   c00009
e12   c00009
e10   c00010
e02   c00011
e03   c00011
e05   c00011
e12   c00012
e06   c00012

我拥有的sql语句是

  select E.Name, D.ConfID as "Number of Conferences" 
     from Employee_C E  left outer join Deals_C D on E.eid = D.eid group by E.eid;

错误:

选择 E.Name、D.ConfID 作为“会议数量” * 第 1 行出错:ORA-00979:不是 GROUP BY 表达式

请帮忙!谢谢你

4

1 回答 1

1

您缺少聚合函数,并且您GROUP BY在不在SELECT列表中的列上使用 a。GROUP BY E.Name由于该列在选择中,因此您需要:

select E.Name, count(D.ConfID) as "Number of Conferences" 
from Employee_C E  
left outer join Deals_C D 
  on E.eid = D.eid 
group by E.Name;

请参阅带有演示的 SQL Fiddle

于 2013-03-26T18:16:04.887 回答