我们有一个大的订单表,在处理时按PurchaseOrderNumber、AccountNumber和ProductType分组。客户端请求我们基于InsertionTimestamp处理这些订单。
这是我们使用的查询,它工作得很好,但需要在客户端请求时进行更改。
Select Purchase_Order_Number, Account_Number, Max(LineNumber) LineNumber, Product_Type
From dbo.PDF_Orders_Validation
Where BotReady = 'Y'
Group By Purchase_Order_Number, Account_Number, Product_Type
我试过的都没用…
Select Purchase_Order_Number, Account_Number, Max(LineNumber) LineNumber, Product_Type
From dbo.PDF_Orders_Validation
Where BotReady = ''
Group By Purchase_Order_Number, Account_Number, Product_Type
Order By InsertionTimestamp
我也试过这个…
Select Purchase_Order_Number, Account_Number, Max(LineNumber) LineNumber, Product_Type
From dbo.PDF_Orders_Validation
Where BotReady = ''
Group By Purchase_Order_Number, Account_Number, Product_Type, InsertionTimestamp
Order By InsertionTimestamp
…这是有效的,但创建了太多的行,并可能导致重复的订单。
我需要的是保留原始查询,但只是通过InsertionTimestamp按升序重新排序。
如果有任何帮助,我将不胜感激。
你试过了吗?
Select Purchase_Order_Number, Account_Number, Max(LineNumber) LineNumber, Product_Type
From dbo.PDF_Orders_Validation
Where BotReady = ''
Group By Purchase_Order_Number, Account_Number, Product_Type
Order By MAX(InsertionTimestamp)
注意——不确定你的处理管道,所以你可能想要MIN()而不是MAX()