required query


I have the table with following details.

 EMployee details
==================   empid  empname        comments             score

1           1            abc                     "hi man"              1

2           1             bbc                     "hi boy"              4

3            1             bbc                     "hi girl"              3

4             2             def                     "come here"     -2

5            2              ggf                     "go there"            4

6            2               dgf                       "go where"       -1

Here i have empid with  1 and 2  and go on... now for each and every employee

i want to get his last comment and Average of his score details and his least
score for which comment he got.

 for eg. i have to get as below for above table      empid            empname               comments             Averagescore     Least Score

3                 1                   bbc                          "hi girl"                       8/3= 2.666            1
6                  2                  dgf                            "go where"                +1/3= 0.333         -1

can you please guide me the query how to get it.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

These results:
3      1      bbc      "hi girl"      3       1      2.666666      1
6      2      dgf      "go where"     -1      1      0.333333      -2

Open in new window

Produced by this query:
       , row_number() over (partition BY empid ORDER BY s_no DESC) AS rn
       , avg(score * 1.0)  over (partition BY empid) AS av_score
       , min(score)  over (partition BY empid) AS min_score
       FROM EMployee_Details
      ) AS Info
WHERE rn = 1

Open in new window

available to use at:!3/c6cf8/7

nb: pl. replace "select *" with the columns you do need/want
and field converted to s_no, please adjust for true field and table names

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
praveen1981Author Commented:
Many thanks..
a pleasure.

May I ask why only "good"? Did I miss something?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.