0

早上好:我有这个查询,但我需要它给我每个订单的最后日期/时间。有时每个日期都会多次处理订单......我只想要最后一个实例。这是查询...任何帮助将不胜感激...在此先感谢

SELECT      dbo.fn_GetNotesForOrder(o.orderid) as Notes, o.OrderNumber, ss.statusname, max(oh.EntryDate),  l.locationcode, l.locationname, a.street, a.city, a.province, a.postalcode, oh.UserID

FROM         orders as o
                               INNER JOIN
             OrderHistory as oh on o.OrderID = oh.OrderID
                               INNER JOIN 
             Statuses as ss on ss.StatusID = oh.Status
                               INNER JOIN   
             addresses as a on a.addressid = oh.addressid
                               INNER JOIN
             locations as l on l.locationid = a.locationid

             WHERE     (oh.EntryDate >= CONVERT(DATETIME, '2013-06-24 00:00:00', 102) AND oh.EntryDate < CONVERT(DATETIME, '2013-06-29 00:00:00', 102)) AND 
                      (UserID in ('MAXWELLPAPER\leyre'/*, 'MAXWELLPAPER\ndwyer', 'MAXWELLPAPER\jploeger', 'MAXWELLPAPER\jpquintanilla', 'MAXWELLPAPER\dwatkinson'*/))

             group by o.orderid, o.ordernumber, ss.statusname, l.locationname, l.locationcode, a.street, a.city, a.province, a.postalcode, oh.UserID, oh.entrydate
             order by oh.entrydate
4

0 回答 0