Max From Select

时间:2013-07-04 20:21:34

标签: sql sql-server sql-server-2008

Create proc [dbo].[SpGetPharmacyLogpast]
AS
SELECT  Pharmacylog.PharmcyItemID,Pharmacylog.PastQuantity,Pharmacylog.NowQuantity,Pharmacylog.Amount,Pharmacylog.TotalValue,PharmacyItems.ID  from Pharmacylog
LEFT JOIN PharmacyItems
ON  PharmacyItems.ID=Pharmacylog.PharmcyItemID where PharmacyItems.ItemID=8

RETURN

我需要根据Pharmacylog.pharmacyItemID

获取此选择的Max

1 个答案:

答案 0 :(得分:1)

我同意@lamak的问题。

但猜测:

Create proc [dbo].[SpGetPharmacyLogpast]
AS
SELECT  TOP 1 Pharmacylog.PharmcyItemID,Pharmacylog.PastQuantity,Pharmacylog.NowQuantity,Pharmacylog.Amount,Pharmacylog.TotalValue,PharmacyItems.ID  
from Pharmacylog 
LEFT JOIN PharmacyItems
ON  PharmacyItems.ID=Pharmacylog.PharmcyItemID 
where PharmacyItems.ItemID=8
ORDER BY Pharmacylog.PharmcyItemID DESC 
RETURN