School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,172 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,555 people online right now. Registration is fast and FREE... Join Now!




SQL question

 

SQL question

quick2u

2 Jul, 2009 - 08:11 AM
Post #1

New D.I.C Head
*

Joined: 29 Jun, 2009
Posts: 1

I have to answer this question -

Calculate the maximum salary for exempt employees and the maximum salary for non-exempt employees in ONE query.

I wrote this statement -

CODE
select max(salary) from employee join job_title on employee.job_title_id = job_title.job_title_id where exempt_status = 'non_exempt_status'


I want to know is this corrent. I am on another computer that does not have SQL on it and just want to know about this question.


User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 2)

corliss

RE: SQL Question

2 Jul, 2009 - 08:52 AM
Post #2

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 170



Thanked: 1 times
Dream Kudos: 50
My Contributions
CODE
select max(salary) from employee join job_title on employee.job_title_id = job_title.job_title_id where exempt_status = 'non_exempt_status'

This code only returns the max salarys for employees who have non-exempt status.
I would suggest grouping by exempt_status.
Also...what table is exempt_status coming from is it employee.exempt_status or job_title.exempt_status?

Assuming that he exempt_status is coming from job_title table:
CODE

select max(employee.salary) as salary, job_title.exempt_status
from employee
join job_title on
employee.job_title_id = job_title.job_title_id
group by job_title.exempt_status




This post has been edited by corliss: 2 Jul, 2009 - 09:07 AM
User is offlineProfile CardPM
+Quote Post

CamoDeveloper

RE: SQL Question

2 Jul, 2009 - 09:07 AM
Post #3

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
For that question yes, that statement is correct. You might need to add a LEFT, RIGHT, or INNER to the join, but I'm sure it will be LEFT for this statement.
CODE

SELECT
    MAX(salary)
FROM
    employee
    LEFT JOIN job_title ON employee.job_title_id = job_title.job_title_id
WHERE
    exempt_status = 'non_exempt_status'


If you want to calculate all of the salaries for the employess, use COUNT()
CODE

SELECT
    COUNT(salary)
FROM
    employee
    LEFT JOIN job_title ON employee.job_title_id = job_title.job_title_id
WHERE
    exempt_status = 'non_exempt_status'


~Camo
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:47PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month