Question

Calculate Syntax

Asked by: Tojo

1.      Calculate the total payroll of exempt and non-exempt employees
2.      Calculate the number of exempt and non-exempt employees there are, by job title.        The results should be sorted in descending order.
3.      Calculate the average salary for all employees.
4.      Calculate the average, minimum and maximum salary for exempt employees.
5.      Calculate the difference between the maximum and minimum salaries for the non-exempt employees.
6.      Calculate the minimum salary for exempt employees and the maximum salary for non-exempt employees.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-02 at 14:31:13ID24865520
Tags

SQL

Topics

SQL Query Syntax

,

SQL Server 2008

Participating Experts
4
Points
125
Comments
24

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Calculation payroll
    This program is supposed to calculate payroll. Been struggnling around for hours There is a problem with the calculation fonction. It returns 0 like the calculation isn't working. Any help would be appreciated. Here are the requirements: The program requirements are: · ...
  2. SQL avg Salary into exempt or non exempt columns
    SELECT AVG(emp_Salary) as Exempt, AVG(emp_Salary) as Non_Exempt FROM NEWTABLE WHERE (((NEWTABLE.Exempt_Status)='n')); This is returning two columns exempt and non_exempt with the same data AVG(emp_Salary). I want to split my columns. if exempt status = n place avg sal...
  3. Access SQL avg Salary into exempt or non exempt columns
    SELECT AVG(emp_Salary) as Exempt, AVG(emp_Salary) as Non_Exempt FROM NEWTABLE WHERE (((NEWTABLE.Exempt_Status)='n')); This is returning two columns exempt and non_exempt with the same data AVG(emp_Salary). I want to split my columns. if exempt status = n place avg sal...
  4. averageing a column without the highest salary
    I have a sheet with the salaries of my office staff in c1, c2, c3, c4, c5, c6, c7 and c8. I have the average of their salaries by calculating =average(c1:c8) in cell c24. What I want is the average of their salaries without the highest paid person. Right now I do this by h...
  5. Calculate Syntax
    1) I would like to calculate the average salary of all the employee in my employee table. Can I use Last_name or Social_Security? 2) I also need to calculate the maximum salary of all the employees. What is the syntax for this? 3)Lastly, I need to calculate the maxumu...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: aneeshattingalPosted on 2009-11-02 at 14:32:29ID: 25724502

seems like an assignment question ?

 

by: TojoPosted on 2009-11-02 at 14:58:28ID: 25724671

I just wanted some direction. I didn't ask for anyone to do any work for me.

 

by: angelIIIPosted on 2009-11-02 at 15:01:55ID: 25724691

>I didn't ask for anyone to do any work for me.
seriously, you did indeed not ask for anything...
just posted the assignment questions.

anyhow, the directions are this:
* you need some WHERE clause to limit the rows eventually
* you need some analytcal functions (like SUM, AVG, MIN, MAX ... ) to "calculate"
* you might need the GROUP BY syntax

 

by: TojoPosted on 2009-11-02 at 15:02:49ID: 25724697

Mybe I wasn't clear, but it's this website here to help?

 

by: angelIIIPosted on 2009-11-02 at 15:06:49ID: 25724729

>but it's this website here to help?
yes.

>Mybe I wasn't clear,
indeed, not clear.

you might want to review the site's guidelines, which states that direct "help" (aka giving solutions for homework & co) are not allowed.

so, as you asked, assistance is fine and will be given, but not the plain SQL.
do some work, post the sql you build, and we shall get you to the final solution.

 

by: TojoPosted on 2009-11-02 at 15:09:44ID: 25724750

So I need somthing like this;

SELECT exempt and non-exempt employees as "Total wages"
FROM Employee
GROUP BY Job_titlet;

 

by: TojoPosted on 2009-11-02 at 15:12:35ID: 25724763

I am not in school!!! I am trying to learn this on my own so I can add this to the thing that I can do.

 

by: angelIIIPosted on 2009-11-02 at 15:13:43ID: 25724768

ok, you start with question 1:
>1.      Calculate the total payroll of exempt and non-exempt employees

to solve this, you have to start identifying the entities from the sentence:
* employee   => table
* exempt/non-exempt  => column
* payroll   => column/table

so, start putting "names" on those entities (aka, clarify the table schema involved)

 

by: TojoPosted on 2009-11-02 at 15:14:04ID: 25724769

Sorry that I was looking for help!!! I want do that again...Have a nice day.

 

by: angelIIIPosted on 2009-11-02 at 15:15:23ID: 25724779

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
    Chinese Proverb

 

by: mwvisa1Posted on 2009-11-02 at 15:29:10ID: 25724875

Not sure why you are walking away (per your last comment), Tojo, as a3 appears to be ready to help guide you through to completion.  The advice he gave you is beyond the call of duty.  If we simply post code here, do you learn anything?  And if you don't, did we help?  Conversely, I guarantee you will learn a great deal from him if you go through the process with him step by step doing your part to actually do some of the work.  He is very good in the art of SQL if you are new here and have not yet familiarized yourself with him.  You will find no better mentor.  Given you have a number of questions already PAQ'd here but don't know where to start on this should be an indication that you need to pick a new approach and a3 is offering you that opportunity with not just one of but "the" best as your guide!

Just my personal opinion.  Take it for what it is worth to you...

Best regards and happy coding,
M-1


 

by: angelIIIPosted on 2009-11-02 at 15:33:03ID: 25724897

thanks for the support, M-1
please note that I am about to leave the keyboard for a couple of hours (getting some sleep :)
a3

 

by: TojoPosted on 2009-11-02 at 17:20:12ID: 25725409

mwvisa1 I did ask for help!!! The only way a person can learn is by doing. I want to learn and if he would have ask for me to go into more detail of my problem, I would have. An expert is defined  as a person who doesn't always have the answer.  I also know that I will always help anyone I can, because doing that will help  me to increase my knowledge. These traits, experience, knowing limits and learning through helping others, are what I think makes the core of an expert. An expert will not always have the answer, but if he or she works hard to found a good solution to the problem, then they would always be considered an expert.

 

by: mwvisa1Posted on 2009-11-02 at 19:22:07ID: 25725826

Agreed.  a3 is definitely such a person, so again think there was just a miscommunication and I am glad you are still around as I was worried you had left.  We are tasked to uphold the members agreement and so the initial comments were not intended to indicate we would not help but to say that posting what appears to be a homework assignment with no specific question was inappropriate.

But, anyway, if you would like assistance in this matter, please provide the table structure.  Some sample data and your expected results with your exact issue with getting this done and we can help from there.

If you find that the 6 points above you have 6 different issues with, then you should break this up into different questions as previously advised.

However, after you provide more detail and what you have tried, you may be able to frame for us the common problem between all 6 and we can approach things from that standpoint.


Regards,
M-1

 

by: mwvisa1Posted on 2009-11-02 at 20:29:19ID: 25726059

And actually before we go too far and forget, angel eyes actual gave you some directions here that should fit all 6 items.

http:#25724691

 

by: TojoPosted on 2009-11-03 at 00:02:06ID: 25726822

Ok I am tring to calculate the number of exempt and non-exempt employees there are, by job title.        and sorted the data in descending order. This is what I have.

SELECT COUNT (Exempt_Non_Exempt_Status) FROM Job_title j INNER JOIN
      Employee e ON j.Job_title = E.Job_title
ORDER BY Job_title DESC;


 

by: Sharath_123Posted on 2009-11-03 at 00:22:12ID: 25726903

Is Exempt_Non_Exempt_Status a column in your job_title or employee table?

 

by: angelIIIPosted on 2009-11-03 at 00:22:52ID: 25726905

Tojo,

>  to calculate the number of exempt and non-exempt employees
as I don't know your table schema, you have to clarify, for me, how the "exempt" is defined in the data.
without that, I cannot "fix" your code, I can only see that it is incomplete, but that, you are aware yourself.

>by job title
you will need to GROUP BY by job title ... and add the column in the select list also

> and sorted the data in descending order
in descending order of "what"? in your sql, you order by the "job title", is that really the "requirement"?
usually, the request is like "order by the [count] descending". Anyhow, the ORDER BY is correct there.

>ON j.Job_title = E.Job_title
this sounds surprising... if the job_title is already in the employee table, why join to job_title table?
this can be answered by clarifying the table schema with the data...


 

by: TojoPosted on 2009-11-03 at 00:58:27ID: 25727091

Mybe seeing what I have will help.

CREATE TABLE Job_title
(
[Job_ID] int PRIMARY KEY IDENTITY(1,1),
[Job_title] varchar(50) NOT NULL,
[High_wage] money NOT NULL,
[Low_wage] money NOT NULL,
[Exempt_Non_Exempt_Status] varchar(20) NOT NULL,
)
GO

INSERT INTO Job_title
VALUES('Accounting Clerk',16.50,11.00,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Assistant Manager',57.00,33.00,'Exempt');
 
INSERT INTO Job_title
VALUES('Bagger',10.00,6.75,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Cashier',11.75,7.25,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Computer Support Specialist',24.50,13.75,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Dir. of Fin. & Acct.',120000,50000,'Exempt');
 
INSERT INTO Job_title
VALUES('Asst.-Bakery & Pastry',11.75,7.25,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Asst.-Butchers & Seafood Specialists',11.75,7.25,'Non-Exempt');
 
INSERT INTO Job_title
VALUES('Stocker',11.75,7.25,'Non-Exempt');
 

CREATE TABLE Employee
(
[SSN] varchar(9) not null primary key,
[LastName] varchar(25) NOT NULL,
[FirstName] varchar(25) NOT NULL,
[Address] varchar(40) NOT NULL,
[City] varchar(15) NOT NULL,
[State] char(2) NOT NULL,
[Telephone_area_code] varchar(3) NOT NULL,
[Telephone_number] varchar(8) NOT NULL,
[Zipcode] varchar(5) NOT NULL,
[Job_title] varchar(50) NOT NULL,
[DateOfBirth]datetime NOT NULL,
[Hire_date] datetime NOT NULL,
[Wage] money NOT NULL,
[Job_ID] int NOT NULL REFERENCES Job_title(Job_ID)
)
GO
 
   
INSERT INTO Employee
VALUES('555555551','Edleman','Glenn','175 Bishops Lane','LaJolla','CA',
     '619','555-0199','92037','Cashier','01/26/1965','10/7/2003',10.75,'1');
     
INSERT INTO Employee
VALUES('555555552','McMullen','Eric','763 Church St.','Lemon Grove', 'CA',
     '619','555-0133','91945','Bagger','03/16/1969','11/1/2002',6.75,'2');
     
INSERT INTO Employee
VALUES('555555553','Slentz', 'Raj','123 Torrey Dr.','Clairmont','CA','619','555-0123','91711',
     'Assistant Manager','05/26/1972','6/1/2000',48000,'3');
     
INSERT INTO Employee
VALUES('555555554','Broun','Erin','2045 Parkway Apt. 2B','Encinitas','CA','760',
    '555-0100','92024','Bagger','12/05/1966','3/12/2003',6.75,'4');
   
INSERT INTO Employee
VALUES('555555555','Carpenter','Donald','927 Second St.','Encinitas','CA','619',
    '555-0154','92024','Stocker','07/14/1967','11/1/2003',7.50,'5');
   
INSERT INTO Employee
VALUES('555555556','Esquivez','David','10983 N. Coast Hwy Apt. 902','Encinitas',
    'CA','760','555-0108','92024','Asst.-Butchers & Seafood Specialists','06/26/1970',
    '7/25/2003',9.25,'6');
   
INSERT INTO Employee
VALUES('555555557','Sharp','Nancy','10793 Montecino Rd.','Ramona','CA',
    '858','555-0135','92065','Cashier','09/09/1968','7/12/2003',10.50,'7');
   
INSERT INTO Employee
VALUES('555555558','Avery','Ledonna','198 Governor Dr.','Del Mar','CA',
   '619','555-0135','92014','Asst.-Bakery & Pastry','01/31/1965','3/01/2003',11.00,'8');
   
INSERT INTO Employee
VALUES('555555559','Tyink','Thomas','87592 Pacific Heights BLVD.','Del Mar','CA',
   '858','555-0159','92014','Asst.-Bakery & Pastry','11/26/1966','4/01/2001',9.75,'9');

Select * from employee
Select * from job_title
SELECT 'FirstName', 'LastName' FROM Employee

SELECT * FROM Job_title j INNER JOIN
      Employee e ON j.Job_ID = E.Job_ID
WHERE j.High_wage BETWEEN $6.00 AND $18.00

SELECT * FROM Job_title j INNER JOIN
      Employee e ON j.Job_ID = E.Job_ID
WHERE e.Zipcode IN ('91945', '92024')

SELECT * FROM Job_title j INNER JOIN
      Employee e ON j.Job_ID = E.Job_ID
WHERE e.Telephone_area_code LIKE '619%' OR  e.Telephone_area_code LIKE '858%'

UPDATE Employee SET DateOfBirth='12/23/2009' WHERE SSN = 555555555

SELECT * FROM Employee WHERE DateDiff(Year, DateOfBirth, GetDate() )  > 40

SELECT LastName FROM Employee ORDER BY Job_title

SELECT * FROM Job_title j INNER JOIN
      Employee e ON j.Job_ID = E.Job_ID
ORDER BY J.High_wage

 

by: angelIIIPosted on 2009-11-03 at 01:03:52ID: 25727109

yes, that clarifies ALL.

so, now I see this:
[Exempt_Non_Exempt_Status] is a column in the job-title table, hence the join is indeed required.

what do you think about this:

SELECT j.Job_title
     , j.Exempt_Non_Exempt_Status
     , COUNT(*)
 FROM Job_title j 
 JOIN Employee e 
  ON j.Job_title = e.Job_title
GROUP BY j.Job_title, j.Exempt_Non_Exempt_Status
ORDER BY j.Job_title DESC, j.Exempt_Non_Exempt_Status
;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: TojoPosted on 2009-11-03 at 01:06:05ID: 25727114

in descending order of "what"? in your sql, you order by the "job title", is that really the "requirement"?

No, I wanted to see if it can be done and the descending order can be by Job_ID

 

by: TojoPosted on 2009-11-03 at 01:08:24ID: 25727129

Thats works. Thanks for your help!!!

 

by: mwvisa1Posted on 2009-11-03 at 03:47:33ID: 25727960

Nice work.
Best regards and happy coding,
M-1

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...