是这样的,有一个表有casno,sampledate,conc(物质编号,采样时间,浓度)三个字段,其中casno和sampledate为联合主键,共同决定一个浓度值。
我想查询【每种物质在最近的日期的浓度,然后按浓度排序各种物质】,我的思路是【按casno分组,查询最大的sampledate及其对应的conc,最后对conc排序】,所以我写了一个查询select casno, era, max(sampledate)
from xx
group by casno
order by era大家都知道,这明显不对。所以菜鸟请教大家了……我知道很简单的,但自己实在无能为力。谢谢
我想查询【每种物质在最近的日期的浓度,然后按浓度排序各种物质】,我的思路是【按casno分组,查询最大的sampledate及其对应的conc,最后对conc排序】,所以我写了一个查询select casno, era, max(sampledate)
from xx
group by casno
order by era大家都知道,这明显不对。所以菜鸟请教大家了……我知道很简单的,但自己实在无能为力。谢谢
where not exists(select 1 from tb where casno=a.casno and sampledate>a.sampledate)
order by era
from xx t
where sampledate=(select max(sampledate) from xx where casno=t.casno)
order by conc