Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a view which returns duplicate rows having field performance, which can be 1,2,3 or 4. I need to select only rows which is having max performance. How to do this ? Tried this :

View :

enter image description here

results needed as follows :

enter image description here

So basically for each employee number group, I need to fetch what is max calender value and corresponding performance value

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
241 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can express

the employee record with the highest performance

as:

there is no record (for this employee) with a higher performance

And that gives:

SELECT * FROM employee e
WHERE NOT EXISTS (
   SELECT *
   FROM employee nx
   WHERE nx.employee_nr = e.employee_number
   AND nx.performance > e.performance
   );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...