Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !

 Online : 12629 |  Welcome, Guest!   Register  Login
Home > Forums > Sql Server > Accessing column data in database and finding the avg,min,max of salary att ...

# Accessing column data in database and finding the avg,min,max of salary attribute in Employee table

Replies: 5 | Posted by: Chvrsri on 10/22/2010 | Category: Sql Server Forums | Views: 964 | Status: [Member] [Moderator] [MVP] | Points: 10

Hi all,

my table format is in this form ::
empname salary merit
abc 1000 good
def 2000 good
hjg 3000 good

Now i want to display in this format

good maximum(in percentage)
minimum(in percentage)
average(in percentage)

minimum(in percentage)
average(in percentage)

these 3 values must be calculated considering all the employees.

That means how many maximum persons have good merit, minimum persons having good merit,average persons having good merit...

It must be in a genric way such that in future i may increase merit type i wnt be only for good and bad.... Hope all understood my problem...

Help is greately appreciated.Thanks in advance

With Regards

Thanks,

 Responses below this ad Get hundreds of .NET Tips and Tricks videos

## Replies

 T.saravanan   Posted on: 10/22/2010 11:03:07 AM Level: Silver | Status: [Member] [MVP] | Points: 50

Hi Srikanth,

Using StoredProcedure you can achieve it.I think you said based on salary.
Here i am give some idea for your reference.

```Declare @maxgood decimal
Declare @countgood decimal
Set @maxgood =(Select Max(Salary) from table1 where merit='good')
Set @countgood=(Select Count(*) from table1 where merit='good' and Salary=@maxgood)
Select (@maxgood/ @countgood) AS [PerofMaxGood]   // You got Percentage of Maximum Good ```

But you told in future merit type will be increase.
So first using temp table you get all the type of merit and then to pass one by one into the line
Select Max(Salary) from table1 where merit=@merit

Cheers :)

Thanks,
T.Saravanan

 Chvrsri   Posted on: 10/25/2010 1:24:38 AM Level: Silver | Status: [Member] [Moderator] [MVP] | Points: 25

Thanq so much for the response but still there is an issue.I need to represent those values in terms of rows.
That means in this way

Good
Max=Maximum Good Percentage
Min=Minimum Good Percentage
Avg=Average Good Percentage

Using a Single Query even it is fine using a Stored Procedure

Thanks,

 T.saravanan   Posted on: 10/25/2010 4:52:50 AM Level: Silver | Status: [Member] [MVP] | Points: 25

Hi Srikanth,

What did you try? Can you give your code here?

Thanks,
T.Saravanan

 Chvrsri   Posted on: 10/25/2010 5:15:54 AM Level: Silver | Status: [Member] [Moderator] [MVP] | Points: 25

I cannot share the actual code because it is Confidential . Even i just want the logic. To implement internal functionality of my project. Hope u understand.
Any how i got the answer,, i did that using the approach u said

i created a temporary table where in which i used variables to update my percentage score for different merits
and then applied a while loop to loop through the values of the salaries and applied the attributes MIN,MAX,AVG
by this way i achived my requirement.

Iam very much thank ful to you, u gave me the idea of solving this .

Cheers!!!!

Thanks,

 T.saravanan   Posted on: 10/25/2010 5:30:16 AM Level: Silver | Status: [Member] [MVP] | Points: 25

Hi Srikanth,

Ok.Its not a problem.
Good, I am also said this way of approach.Any how you got an answer.I am happy.

Cheers :)

Thanks,
T.Saravanan