Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 12629 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > Accessing column data in database and finding the avg,min,max of salary att ...
Chvrsri

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
xyz 0 bad


Now i want to display in this format

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

bad maximum(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...
Similarly with bad 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
CH.V.Radha Srikanth

Thanks,
Radha Srikanth


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

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

Resolved

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

If any doubt ask to me i will help you.

Cheers :)



Thanks,
T.Saravanan

Chvrsri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Chvrsri
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

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

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



Thanks,
Radha Srikanth

Chvrsri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

T.saravanan
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, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Chvrsri
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,
Radha Srikanth

Chvrsri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

T.saravanan
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

Chvrsri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 7:34:07 AM