Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AbdullahDar
Starting Member
2 Posts |
Posted - 2011-05-05 : 08:46:31
|
Hi all i am new to sql. I need help with a query.To get top 10 employees between a specific date i am using this query:SELECT DISTINCT TOP 20 Employee, ROUND(OverAllPercentage, 2) AS Grade, FROM Table_NameWHERE Date_Field BETWEEN @From AND @ToORDER BY Grade DESCIts output is like:Employee Grade Employee1 100Employee2 90Employee3 90Employee4 80Now the problem is that an employee can come at top by getting only one high grade, and there might be employees who have taken same grade more than one time, so they should appear one top.I want to add field which should tell how many time that employee has appeared in database and should return top employees by calculating there average. If two employees have same averages score, then that employee should come at top that has appeared more than the other in the database.So the output should be like:Employee No of appearences GradeEmployee1 5 100Employee2 2 100Employee3 3 80 Abdullah Dar |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-05-05 : 10:59:01
|
which version you are using?--------------------------http://connectsql.blogspot.com/ |
|
|
AbdullahDar
Starting Member
2 Posts |
Posted - 2011-05-05 : 15:08:38
|
sql server 2000!Abdullah Dar |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2011-05-13 : 16:54:29
|
Select Employee, [No of appearences], Grade order by Grade, [No of appearences]Srinika |
|
|
|
|
|