0

I'm sure this is super-easy, I just haven't drunk enough coffee today....

So, I have a single table with a few columns, like:

NAME1 val1 val2 val2
NAME2 val1 val2 val3

There are only about 20 distinct names the first column holds, the values are real but duplicates happen sometimes. I have to find the best ranking row for each distinct NAME. The ranking is done by sorting first by val1 then val2 then val3

Edit: So here is an example:

Ben    2.1 1.0 0.6
Ben    0.1 1.0 0.6
Ben    2.1 0.9 0.1 
Alice  2.1 0.9 0.1 
Alice  2.0 0.9 0.1 

The answer should be:

Ben    2.1 1.0 0.6
Alice  2.1 0.9 0.1 
0

2 Answers 2

1
select [name],max(val1) as val1,max(val2) as val2,max(val3)as val3 from sql_select group by [name] order by val1 desc, val2 desc, val3 desc; 
Sign up to request clarification or add additional context in comments.

Comments

0
select * from table order by val1, val2, val3

You didn't document much, can't be more precise until you give more

1 Comment

look at 'desc' to reverse the sort

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.