-2

I have a table with several columns such as "pcode", "completion in %" and "pstatus". For example:

pcode P_Name     completion  subordinate         pstatus
p123  inventory     10%         sanjay           progrssing  
p123  test          20%         komal            progrssing
p124  asd           20%         ritika           progrssing
p124  qwsdf         10%         asd              progrssing

I want to get result with different code with highest complete% with other column. All field are text. I'm using asp.net using c# and msaccess database.

What I'm looking for as a result is:

 pcode P_Name     completion  subordinate         pstatus
  p123  test          20%         komal           progrssing
  p124  asd           20%         ritika          progrssing
casperOne
  • 72,334
  • 18
  • 180
  • 242
user1085240
  • 31
  • 1
  • 4

1 Answers1

1

On the database side, you'll have to filter your data. Following query should help you with that

SELECT t1.[pcode], t1.[P_Name], t.[completion], MAX(t1.[subordinate]) [subordinate], [pstatus]
FROM [YOUR_TABLE] t1
    JOIN 
    (SELECT [pcode], max([completion]) [completion]
    FROM [YOUR_TABLE]
    GROUP BY [pcode]) t
    on t.[pcode] = t1.[pcode] and t.[completion] = t1.[completion]
GROUP BY t1.[pcode], t1.[P_Name], t.[completion], t1.[pstatus]

Note: Concerning the binding part of your question, you'll have to provide more information if you're wiling to get (precise) answers.

nulltoken
  • 60,369
  • 19
  • 132
  • 128