-3

I have a table with the following columns: Policy, ProcessCode, ProcessedOn, GWP (and others)

The table has multiple lines for the same policy based on those 3 other columns with different values.

How can I select only the policies with the MAX value on column GWP ?

Thanks! see example of data here

encrypted
  • 1
  • 3

1 Answers1

-1

You can use order by and top:

select top (1) t.*
from t
order by gwp desc;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 2
    *cough* Close as Duplicate. *cough* – Thom A Aug 05 '21 at 12:23
  • not ok. I have multiple lines with other policies in the table. using top (1) and order by policy ; gwp desc will display only 1 policy – encrypted Aug 05 '21 at 12:28
  • That is what you ask for, @encrypted ; 1 row... – Thom A Aug 05 '21 at 12:42
  • @larnu sorry, I`m new to stackoverflow. I've added a new image of data. – encrypted Aug 05 '21 at 12:43
  • Images don't explain anything here, @encrypted . – Thom A Aug 05 '21 at 12:44
  • Ok. I have the following columns: policy, ProcessCode, ProcessedOn and GWP. Each policy may have multiple lines. I have to select only the lines with MAX GWP for each policy – encrypted Aug 05 '21 at 12:45
  • Use the [edit](https://stackoverflow.com/posts/68666502/edit) to improve your question, @encrypted . As it stands, you want the "top" row and those duplicates tell you how to do that. – Thom A Aug 05 '21 at 12:46
  • I already checked those duplicates, without understanding their answers. – encrypted Aug 05 '21 at 12:48
  • @larnu I've edited my question. can you please mark it as opened ? I didn't figure it out from those 2 other questions mentioned by you. thank you. – encrypted Aug 05 '21 at 12:53
  • 1
    No need to, this is just another duplicate of [this question](https://stackoverflow.com/questions/6841605/get-top-1-row-of-each-group) @encrypted . I've added the dupe to the list. – Thom A Aug 05 '21 at 12:54
  • can you explain me please based on my table ? I cannot figure out the answer from those 2 other question – encrypted Aug 05 '21 at 12:55
  • 1
    All the information is in the answer(s) on the dupe, @encrypted . If you don't understand the answer, I would suggest you post a new question, showing your attempts to implement the solutions on the other question, and explaining why they didn't work. Though, with respect, reading the answers on the linked [duplicate](https://stackoverflow.com/questions/6841605/get-top-1-row-of-each-group) will tell you exactly what you need to do. – Thom A Aug 05 '21 at 12:58
  • cannot add other question today.... – encrypted Aug 05 '21 at 13:01