select buypn,buyid,buydate,buyitem,buyprice,buycurrency from (
select buypn,buyid,buydate,buyitem,buyprice,buycurrency,
row_number() over(partition by buypn order by buydate asc) rn
from buy_file
) t where rn = 1
SELECT xx.* FROM
(
SELECT
FROM 表名
ORDER BY 采购日期 ASC
)xx
GROUP BY xx.料号
ORDER BY xx.采购日期DESC
select a.*
from buy_file a
left join (select buypn
min(buydate)
from buy_file
group by buypn) b
on a.buypn = b.buypn and a.buydate = b.buydate
order by a.buypn