February 28, 2012 at 1:25 pm
Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).
SELECT job_title.job_desc, Employee.last_name, Employee.first_name, Employee.salary
FROM Employee
FULL JOIN job_title
ON Employee.job_desc=job_title.job_desc
UPDATE Employee
SET salary = salary + (salary * (10/100))
WHERE job_desc = ‘Obtains or prepares food items requested by customers in retail food store’
But it's not coming out right. Any ideas? One of my problems is selecting only those employees with a selected job description.
Does anybody know of where online I can go to help me with these as well?
2. Decrease all Exempt employees’ salaries from a certain State by 15%.
3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.
4. Delete any Exempt employees earning a Salary greater than a certain amount.
5. Calculate the maximum salary of all Exempt employees.
6. Calculate the sum of employee salaries for each Job Description from low to high value.
7. Calculate the minimum, maximum, and average salary for each Job_Description.
****I think I can pretty much handle 4-7 but the first 3 really have me stumped.***
The book in my class is like reading French. It's not geared to those who have very little experience in SQL. Thank you for any help you can provide.
February 28, 2012 at 2:05 pm
An update statement doesn't have a select. It should be like:
update a
set a.column = a.column + 1
from Table1 a
inner join table2 b
on a.Col2 = b.col2
February 28, 2012 at 2:46 pm
spro1210 (2/28/2012)
Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).But it's not coming out right. Any ideas?
What does that mean? Are you updating the wrong rows? Is it failing with an error message?
One of my problems is selecting only those employees with a selected job description.
Where job_desc = 'some value you want to find'
Does anybody know of where online I can go to help me with these as well?
2. Decrease all Exempt employees’ salaries from a certain State by 15%.
3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.
Yes, SSC is a good location for learning sql. Since this is obviously homework we are NOT going to spoon feed you. As you said you can handle 4-7 so for 2 and 3, what have you tried?
Keep in mind that we don't have your tables or know what columns are in them so when you post what you have tried you should also post some ddl (create table scripts) and sample data (insert statements). Take a look at the first link in my signature for best practices on posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 28, 2012 at 2:47 pm
For 2 and 3, I made an assumption for your field to determine if Exempt or Not, Employee State of Residence, Employee Hire Date, and Employee Birth Date
--1.Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).
UPDATE Employee
SET salary = salary + (salary * (10/100))
FROM Employee
INNER JOIN job_title
ON Employee.job_desc=job_title.job_desc
WHERE job_desc = 'Obtains or prepares food items requested by customers in retail food store'
--2. Decrease all Exempt employees’ salaries from a certain State by 15%.
UPDATE Employee
SET salary = salary - (salary * (15/100))
FROM Employee
WHERE Exempt = 'Yes' --Change this to reflect how you identify Exempt vs Non-Exempt
And Employee_State = 'WI' --insert your state code here
--3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.
UPDATE Employee
SET salary = salary + (salary * (5/100))
FROM Employee
WHERE Exempt = 'No' --Change this to reflect how you identify Exempt vs Non-Exempt
And DATEDIFF(dd,Date_Hired,GETDATE()) > 1095 --365*3 = 1095, which be be the min days in 3 years, if a leap year it would be 1096.
And (CASE WHEN (DATEADD(year,DATEDIFF(year, Birth_Date ,GETDATE()) , Birth_Date) > GETDATE())
THEN DATEDIFF(year, Birth_Date ,GETDATE()) -1
ELSE DATEDIFF(year, Birth_Date ,GETDATE()) END) < 30
February 28, 2012 at 2:51 pm
Thanks Steve!
I guess I was making it more complicated than it needed to be.
The only other part that I'm stuck on is I have to increase the percentage for only those employees with a certain job description BUT....
there are two tables one for job title and one for employees. The table with the job title is the one with the job description but both the job title and employee table have a job_title column. Is this where I combine the tables and use the WHERE clause? Not sure if I'm making much sense to you. But thanks anyways. lol 😀
February 28, 2012 at 2:52 pm
NVM
February 28, 2012 at 2:54 pm
rlswisher (2/28/2012)
For 2 and 3, I made an assumption for your field to determine if Exempt or Not, Employee State of Residence, Employee Hire Date, and Employee Birth Date--1.Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).
UPDATE Employee
SET salary = salary + (salary * (10/100))
FROM Employee
INNER JOIN job_title
ON Employee.job_desc=job_title.job_desc
WHERE job_desc = 'Obtains or prepares food items requested by customers in retail food store'
--2. Decrease all Exempt employees’ salaries from a certain State by 15%.
UPDATE Employee
SET salary = salary - (salary * (15/100))
FROM Employee
WHERE Exempt = 'Yes' --Change this to reflect how you identify Exempt vs Non-Exempt
And Employee_State = 'WI' --insert your state code here
--3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.
UPDATE Employee
SET salary = salary + (salary * (5/100))
FROM Employee
WHERE Exempt = 'No' --Change this to reflect how you identify Exempt vs Non-Exempt
And DATEDIFF(dd,Date_Hired,GETDATE()) > 1095 --365*3 = 1095, which be be the min days in 3 years, if a leap year it would be 1096.
And (CASE WHEN (DATEADD(year,DATEDIFF(year, Birth_Date ,GETDATE()) , Birth_Date) > GETDATE())
THEN DATEDIFF(year, Birth_Date ,GETDATE()) -1
ELSE DATEDIFF(year, Birth_Date ,GETDATE()) END) < 30
Or you could make the calculations a lot easier to write and understand.
1. salary = salary * 1.1
--I assume the description is actually in the Job title table, so you need to join on title = title.
2. salary = salary * .85
3. salary = salary * 1.05
and HireDate < dateadd(yy, getdate(), -3)
and BirthDate < dateadd(yy, getdate(), -30)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 28, 2012 at 2:55 pm
change the join in query 1 that I gave you to
where Employee.JobTitle = JobTitle.JobTitle
instead of joining on JobDesc
February 28, 2012 at 2:57 pm
Sean,
Thanks for your help. FYI...didn't ask for any spoon feeding but I do like Vanilla ice cream. LOL.
No, just wanted a little guidance. I was stuck on the first one for some time and remembered that this was a good site to go to.
Thank you....when I go home I'm going to go through all of the responses and go from there. 😀
February 28, 2012 at 3:01 pm
rlswisher or Grasshoper (sorry still new to these forums) lol.
You read my mind. I was just going to ask you if it was going to give me an error b/c both tables do not have job_desc.
Thank you so much for your help. I really appreciate it.
Just out of curiosity. Did you learn this through a class? I'm taking an online class and it's hard when you can't get in touch with the professor for days. Do you know of any really good sources for someone not as advanced as you. I'm going to school online for my BS in IT/Database Development and really want to get good at SQL but it's not as easy I thought....at least not all of it.
Thanks again! :-):-D
February 28, 2012 at 3:15 pm
My pleasure!
I have learned sql in many ways. I learned some basics via class at my work back in the day when I first got started.
Also have learned from years of querying and looking for what I need online.
You can always start here, if you notice on the Navigation to the left there is a Scripts link. There are useful hints here.
And there is ALWAYS!!! the trusted Google! 😀
StackOverflow is another good reference.
My favorites, in no order, are
SqlServerCentral
StackOverflow
February 28, 2012 at 6:32 pm
This is a great place to be. I spend whatever free time I have during the day reading through the forums. There are some mighty talented folks here that seem to take great pleasure in helping us learn. It's a wonderful thing.
You might want to go through the "Stairways" on this site - see left nav. Good stuff.
February 29, 2012 at 7:10 am
spro1210 (2/28/2012)
Sean,Thanks for your help. FYI...didn't ask for any spoon feeding but I do like Vanilla ice cream. LOL.
No, just wanted a little guidance. I was stuck on the first one for some time and remembered that this was a good site to go to.
Thank you....when I go home I'm going to go through all of the responses and go from there. 😀
You are quite welcome. Hope it was some help and more importantly that you learned something from it.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 1, 2012 at 9:47 am
I just kindo skimmed the thread so I hope I'm not repeating someone else... at this stage of learning, I STRONGLY suggest building your queries as select queries and verify that they are operating on the rows you want in ways you expect. After that, it's simple to convert to update/delete.
March 1, 2012 at 10:57 am
Excellent point and good teaching.
Love the name, Mr. Pants.
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply