0

我正在使用 SqlLite。我的表由jobno's 和ondate创建它的时间 ( ) 组成。我想从每个组中选择最近的 jobno

ondate不是标准日期格式。它包含这种格式的值09/08/2013 04:04:30 所以我做了ondate一点不同的排序。

select r1.jobno, r1.ondate 
from reports r1 
where(
     select r2.jobno 
     from reports r2 
     where r1.jobno=r2.jobno 
     ORDER BY 
           substr(r2.ondate,7,4)||
           substr(r2.ondate,1,2)||
           substr(r2.ondate,4,2)||
           substr(r2.ondate,11) desc
    ) 
group by r1.jobno <=1

排序ondate是正确的。它得到正确订购。
相关查询是错误的,它没有给我正确的输出。谁能帮我纠正这个查询。

4

1 回答 1

0
select r1.jobno, r1.ondate 
from reports r1
where
    r1.ondate = (
        select ondate
        from reports as r2 where r2.jobno = r1.jobno
        order by
           substr(r2.ondate,7,4)||
           substr(r2.ondate,1,2)||
           substr(r2.ondate,4,2)||
           substr(r2.ondate,11) desc
        limit 1 
    )
于 2013-09-08T08:29:57.617 回答