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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help required regarding a query

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_Name
WHERE Date_Field BETWEEN @From AND @To
ORDER BY Grade DESC

Its output is like:
Employee Grade
Employee1 100
Employee2 90
Employee3 90
Employee4 80

Now 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 Grade
Employee1 5 100
Employee2 2 100
Employee3 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/
Go to Top of Page

AbdullahDar
Starting Member

2 Posts

Posted - 2011-05-05 : 15:08:38
sql server 2000!

Abdullah Dar
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -