0
Customer_Name      Itemcode Order_Number    Quantity ord    u_es    Avail. Fulfillment%
-----------------------------------------------------------------------------------------------------
oracle blaionuel   1019885  F130238518001   1           CET     0            0.00
oracle blaionuel   1132006  F130238518001   1           CET     1            100.000
oracle blaionuel   1016964  F130238518001   1           CET     0            0.00      

I want to achieve an t-sql query that will introduce another column [Fulfilment% Order Level], which takes the least Fulfillment% of the 3 rows . I am using Mssql 2008 i.e

Customer_Name      Itemcode Order_Number    Quantity ord    u_es    Avail. [Fulfilment% Order Level]
-------------------------------------------------------------------------------------------------
oracle blaionuel   1019885  F130238518001   1           CET     0            0.00
2
  • what about the itemcode and the u_es? how do you pick those values instead of the other ones? Commented Dec 15, 2014 at 11:28
  • 1
    I guess tp asks for the row with the lowest Avail. Fulfillment%. But that's a tie in this case, and I don't know if that means return 2 rows, or how to pick one single row... Commented Dec 15, 2014 at 11:30

1 Answer 1

1

I think you are looking for row_number():

select t.*
from (select t.*,
             row_number() over (partition by customer_name, order_number order by [Fulfillment%] asc) as seqnum
      from table t
     ) t
where seqnum = 1;
Sign up to request clarification or add additional context in comments.

2 Comments

looks like OP need lowest fulfilment% and there is a tie
@NoDisplayName . . . When there is a tie, I assume one of the rows can be chosen arbitrarily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.