ROW_NUMBER() OVER (PARTITION BY b.sMaterialNo ORDER BY a.tStoreInTime DESC)


SELECT c.sMaterialNo,
c.sMaterialName,
c.nACPrice,
c.nTaxRate,
c.tStoreInTime
FROM
(
SELECT b.sMaterialNo,
b.sMaterialName,
b.nACPrice,
b.nTaxRate,
a.tStoreInTime,
ROW_NUMBER() OVER (PARTITION BY b.sMaterialNo ORDER BY a.tStoreInTime DESC) AS new_index
FROM dbo.mmYNInHdr a
JOIN dbo.mmYNInDtl b
ON a.uGUID = b.ummInHdrGUID
WHERE nACPrice > 0
) c
WHERE c.new_index = 1
and (/*Condition*/ )
ORDER BY c.tStoreInTime DESC;

 

SQL取特定几行

select identity(int,1,1) as rownum,* into #tmp  from dbo.mmMaterial 
select *  from #tmp where rownum=2
drop table #tmp

 

posted on 2020-06-05 13:09  RookieBoy666  阅读(162)  评论(0编辑  收藏  举报