Need help with creating query for below case :
Suppose I have a Table with following records
Name Date Time Category CategoryKey
John 10/20/2012 10:00 Low 2
Sam 10/20/2012 10:00 High 4
Harry 10/20/2012 10:00 Medium 1
Michael 10/20/2012 10:00 Grey 3
Rob 10/22/2013 11:00 Low 2
Marry 10/23/2014 12:00 Low 2
Richard 10/23/2014 12:00 Grey 3
Jack 10/24/2015 1:30 High 4
Then If there are multiple Names for same date and time then force select only one record based on following logic and stop when any 1 of the following condition is met.
If Category is Medium then take name
Else If Category is High then take name
Else If Category is Low then take name
Else If Category is Grey then take name
So that the Final result will be
Name Date Time Category CategoryKey
Harry 10/20/2012 10:00 Medium 1
Rob 10/22/2013 11:00 Low 2
Marry 10/23/2014 12:00 Low 2
Jack 10/24/2015 1:30 High 4