SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 please solve this sql query for me.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ramkumarodc
Starting Member

India
5 Posts

Posted - 09/16/2010 :  04:31:49  Show Profile  Reply with Quote
1.Display the manager number and the salary of the lowest paid employee for that manager.
Exclude anyone whose manager is not known. Exclude any groups where the minimum
salary is $6,000 or less. Sort the output in descending order of salary.

2.Write a query to show the employee and the manager ids. The query should populate the manager id as the employee id itself if the employee doesn’t have a manager. In the result set, the Manager list should have the heading “Boss”.

R~K

R~K

webfred
Flowing Fount of Yak Knowledge

Germany
8764 Posts

Posted - 09/16/2010 :  04:40:39  Show Profile  Visit webfred's Homepage  Reply with Quote
Still no answer about what you have tried so far...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 09/16/2010 :  04:41:23  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
SO. Homework question.......

NO. I will not solve the sql query for you.

However, here is how you should start thinking about the problem:

1 Manager Number and salary of the lowest paid employee for that manager.

sounds like a GROUP BY with a MIN aggregate function

Exclude anyone whose manager is not known...

Sounds like a JOIN (an inner join)

.....
.....

And the rest is up to you.

You won't learn anything if you just get the answer from somewhere.

If you try something feel free to show us what you tried -- then you'll get feedback and help.

Good luck


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

ramkumarodc
Starting Member

India
5 Posts

Posted - 09/16/2010 :  05:17:13  Show Profile  Reply with Quote
ok i will try and post the result

R~K
Go to Top of Page

ramkumarodc
Starting Member

India
5 Posts

Posted - 09/16/2010 :  07:52:42  Show Profile  Reply with Quote
can any one give me a syntax for copy a table in oracle using subqueries by renaming the column.

R~K
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 09/16/2010 :  09:08:16  Show Profile  Reply with Quote
If you are working in ORACLE, try here: http://www.dbforums.com/oracle/

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

ramkumarodc
Starting Member

India
5 Posts

Posted - 09/23/2010 :  05:07:46  Show Profile  Reply with Quote
i tried this answer....

1.Display the manager number and the salary of the lowest paid employee for that manager. Exclude anyone whose manager is not known. Exclude any groups where the minimum salary is $6,000 or less. Sort the output in descending order of salary.
Answer:
select mgr, min(sal) from emp where mgr is not null and sal>6000 order by sal desc;

2.Write a query to show the employee and the manager ids. The query should populate the manager id as the employee id itself if the employee doesn’t have a manager. In the result set, the Manager list should have the heading “Boss”.
ANS: select Empid,nvl(mgr,empid)as boss from emp;

R~K

Edited by - ramkumarodc on 09/23/2010 05:14:09
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 09/23/2010 :  05:11:43  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
Not quite.

Hint -- you need a GROUP BY and a HAVING clause to fulfil the requirement.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

rohitvishwakarma
Posting Yak Master

India
232 Posts

Posted - 09/23/2010 :  05:14:14  Show Profile  Reply with Quote
2.Write a query to show the employee and the manager ids. The query should populate the manager id as the employee id itself if the employee doesn’t have a manager. In the result set, the Manager list should have the heading “Boss”.


SELECT empID,CASE WHEN mgr IS NULL THEN empID
ELSE mgrID
END AS [Boss]
FROM emp_A4200
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000