我已经表(t_image)与此列PostgreSQL的 - 如何获得一个行最小值
datacd | imagecode | indexdate
----------------------------------
A | 1 | 20170213
A | 2 | 20170213
A | 3 | 20170214
B | 4 | 20170201
B | 5 | 20170202
期望的结果是这个
datacd | imagecode | indexdate
----------------------------------
A | 1 | 20170213
B | 4 | 20170201
在上表中,我想为每个具有最小索引日期的datacd检索1行
这是我的查询,但结果返回2行,用于datacd A
select *
from (
select datacd, min(indexdate) as indexdate
from t_image
group by datacd
) as t1 inner join t_image as t2 on t2.datacd = t1.datacd and t2.indexdate = t1.indexdate;
http://stackoverflow.com/questions/ tagged/postgresql + most-n-group- –