2

我尝试了 sql 语句的不同变体,但我仍然得到“没有选择行”。我不知道我哪里错了!

这是问题:

我必须列出经理为“Green”的员工组织的会议的标题。

与查询关联的表是:

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

Conference_C桌子:

CONFID              TITLE                     LOCATION          SDATE
------        --------------------       -------------------- ---------
c00001    Hydroinformatics                  Singapore          15-JUN-12
c00002    Ecological_modeling               Berlin             15-JUL-12
c00003    Computational_M                   London             25-MAY-12
c00004    Ecoinformatics                    Boston             22-AUG-12
c00005    Uncertainty_analysis              Athens             10-OCT-12
c00006    Large_databases                   Toronto            13-APR-12
c00007    Systems_analysis                  Boston             23-MAR-12
c00008    Systems_integration               Tokyo              24-FEB-12
c00009    Aquatic_biology                   Helsinki           12-MAY-12
c00010    Information_systems               Paris               08-JAN-12
c00011    Simulation_modeling               Rome                01-SEP-12
c00012    DSS                               Melbourne          18-DEC-12

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 C.Title 
from Conference_C C 
where C.ConfID in (select D.ConfID
                   from  Deals_C D 
                   where D.eid in (select E.eid 
                                   from Employee_C E 
                                   where E.Name = 'Green'));

我得到“没有选择行”

4

2 回答 2

4

您查询的问题是您正在检查错误的员工数据。您的WHERE子句正在检查EIDto theEID时,它​​确实应该检查Deals_C.EIDto the Employees.MID

select C.Title 
from Conference_C C 
inner join
(
  select D.ConfID, e.eid
  from Deals_C D 
  inner join Employee_C e
    on d.EID= e.EID
  where exists (select *
                from Employee_C e2
                where E2.Name = 'Green'
                  and e.mid = e2.eid)
) d
  on c.CONFID = d.CONFID

请参阅SQL Fiddle with Demo

EXISTS查询返回具有姓氏的行,Green但您需要检查Employee_C.MID子查询EID

这也可以写成:

select C.Title 
from Conference_C C 
where C.ConfID in (select D.ConfID
                   from Deals_C D 
                   inner join Employee_C e
                     on d.EID= e.EID
                   where exists (select *
                                 from Employee_C e2
                                 where E2.Name = 'Green'
                                   and e.mid = e2.eid));

请参阅带有演示的 SQL Fiddle

于 2013-03-26T19:03:24.827 回答
0

我刚遇到这个问题。我“没有选择行”的原因仅仅是因为我的 sqlcase 设置为 UPPER 并且我以小写形式查询。即 WHERE empName LIKE '_a%'; 我将 sqlcase 设置为混合并解决了我的问题。似乎引号之间的字符串区分大小写。希望能帮助到你。

于 2016-02-29T22:59:42.793 回答