Home » SQL & PL/SQL » SQL & PL/SQL » SQL query
SQL query [message #404082] Wed, 20 May 2009 05:08 Go to next message
som.sangli
Messages: 3
Registered: May 2009
Junior Member
Hello friends,

I do not get following output.

Query :

List employee name, salary and his income group as 'LOW' or 'HIGH' depending upon the salary amount (If the salary is less than 4000 then he is in 'LOW' income group or else in 'HIGH' income group.)

OUTPUT should be like this:

Ename Salary LOW HIGH
-------------------------------------------------------
SCOTT 3000 LOW
KING 5000 HIGH

Please let me know if u have solution.
Thanks in advance.

----------------
Somnath

[Updated on: Wed, 20 May 2009 05:12]

Report message to a moderator

Re: SQL query [message #404083 is a reply to message #404082] Wed, 20 May 2009 05:10 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
What have you tried so far? This looks like homework, is that the case?
Re: SQL query [message #404086 is a reply to message #404083] Wed, 20 May 2009 05:14 Go to previous messageGo to next message
som.sangli
Messages: 3
Registered: May 2009
Junior Member
I have tried to get output by using CASE and DECODE function but i didn't get output.
Do u have any solution?
Re: SQL query [message #404087 is a reply to message #404086] Wed, 20 May 2009 05:18 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
I have lot's of solutions, but I personally am not prepared to do your homework for you. Show us (by copying your formattedcode and pasting it here between [code]Your code goes here [/code] tags. I'm assuming that you are using the emp table in the scott schema. If this is not the case, then also post a test case (i.e. create table and insert statements to generate a sample of the data that you are working with)

PS please refrain from using IM speak (such as u instead of you) thanks

[Updated on: Wed, 20 May 2009 05:19]

Report message to a moderator

Re: SQL query [message #404088 is a reply to message #404086] Wed, 20 May 2009 05:18 Go to previous messageGo to next message
sr_orcl
Messages: 82
Registered: January 2009
Location: mumbai
Member

Try This query
SELECT ename,
       sal,
       CASE
          WHEN (sal <= 4000) THEN
           'LOW'
          ELSE
           'HIGH'
       END income_group
FROM   emp
Re: SQL query [message #404089 is a reply to message #404088] Wed, 20 May 2009 05:22 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Awesome. Just do the OP's homework for him. Absolutely no point in trying to lead him to the right answer, just plonk it down in front of him just so that you can show how super and clever you are.
Re: SQL query [message #404093 is a reply to message #404088] Wed, 20 May 2009 05:29 Go to previous messageGo to next message
som.sangli
Messages: 3
Registered: May 2009
Junior Member
sr_orcl wrote on Wed, 20 May 2009 15:48
Try This query
SELECT ename,
       sal,
       CASE
          WHEN (sal <= 4000) THEN
           'LOW'
          ELSE
           'HIGH'
       END income_group
FROM   emp



Hi sr_orcl,

earliar, i had tried with CASE WHEN but it had not worked.
U have given really good solution. However it doesn't give required output. I have modified query and i got required output.
I used two CASE statement for two separate columns(LOW and HIGH).
Thanks a lot.

Regards,
Somnath
Re: SQL query [message #404094 is a reply to message #404093] Wed, 20 May 2009 05:35 Go to previous message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Quote:
U have given really good solution. However it doesn't give required output
That would be a bit of an oxymoronic statement surely? If it doesn't give the result, then it isn't a solution. As before, please stop using IM speak. And yet again, you refuse to post the code that you say you have written.
Good luck, I am out.
Previous Topic: Substr and Instr
Next Topic: Triggers
Goto Forum:
  


Current Time: Sun Dec 04 04:21:44 CST 2016

Total time taken to generate the page: 0.04594 seconds