【问题标题】:SQL MAX(dob) not returning in inner join with conditionsSQL MAX(dob) 没有在有条件的内部连接中返回
【发布时间】:2015-04-28 05:39:22
【问题描述】:

在试图找到医生的基本信息(姓名、地址电话等),他们是在诊所工作的最年轻的,但也没有辞职。

我浏览了论坛,发现最好的方法是使用内部联接,但现在它根本不返回任何信息。

select doctorid, surname, given, address, suburb, postcode, phone
from doctor 
inner join (
        select max(dob)
        from doctor
        where resigned is null);

此代码不工作,任何帮助将不胜感激。

【问题讨论】:

  • 内连接语法似乎错误,您没有在此处提及您要连接的字段,@andomar 已正确纠正。

标签: sql oracle join max


【解决方案1】:

inner join 需要 on 子句:

from doctor 
inner join (
    select max(dob) as max_dob
    from doctor
    where resigned is null) filter
on filter.max_dob = doctor.dob

【讨论】:

    【解决方案2】:

    试试这个:

       select d1.doctorid, d1.surname, d1.given, d1.address, 
       d1.suburb, d1.postcode, d1.phone
       from doctor d1 join doctor d2
       on d1.doctorid<> d2.doctorid and d1.dob>=d2.dob
       group by d1.doctorid
       having count(*)= (select count(*)-1 from doctor);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多