Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on sql query within the SQL forums, part of the Databases category; 1. Display employee name and salary as 'Above 1500’ if salary >1500 (using Decode) ‘Below 1500’ if salary ‘Exactly 1500’ If salary=1500 2. Write a query to to find out ...
|
|||||||
|
|||
|
sql query
1. Display employee name and salary as
'Above 1500’ if salary >1500 (using Decode) ‘Below 1500’ if salary<1500 ‘Exactly 1500’ If salary=1500 2. Write a query to to find out number of days in that month for a given date ? |
| Sponsored Links |
|
|||
|
Re: sql query
better to use case, that is more effective
Code:
SELECT EMPNO,ENAME, CASE WHEN SAL>1500 THEN 'ABOVE' WHEN SAL<1500 THEN 'BELOW' WHEN SAL=1500 THEN 'EXACT' END AS REMARK FROM EMP; |
| The Following User Says Thank You to debasisdas For This Useful Post: | ||
|
|||
|
Re: sql query
Hi,
it is some what complex to get your solution using Decode Function.. For your requirement better use case statement..it is advisable.. Anyhow check it out this.. select ename, sum(decode(greatest(SALARY,29000),least(SALARY,30000),1,0)) from employee group by ename; It displays list of ename who r having salary in the range of 29000-30000. |
|
|||
|
Re: sql query
For ur second Query,,
Try this.. SELECT TO_CHAR(LAST_DAY('01-jan-2008'),'dd') from dual; |
| The Following User Says Thank You to ecearund For This Useful Post: | ||
|
|||
|
Re: sql query
Quote:
SELECT TO_CHAR(LAST_DAY('01-jan-2008'),'dd') from dual; sorry, and the above query is working any way thanks for giving support your second query is corect |
|
|||
|
Re: sql query
Hi,
If you need to use the decode function then first you have to create a formula that will evaluate to a single number for each one of your ranges The following code may give you some idea,though I am not sure of the code because I havent run it before posting it to you. SELECT emp_name, decode(trunc (( salary + 1500) / 1500), 1, "BELOW", 2, "EXACT", "ABOVE") as SALARY FROM employees; For the second question,I think the solution provided by the other members is sufficient. |
|
|||
|
Re: sql query
Quote:
Select ename, DECODE (SUBSTR (sal - 1500, 1, 1), '-', 'Below', '0', 'Exact', 'Above' ) From scott.emp
__________________
Sireesha |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Update query using sub query | ravikumar.drk99 | SQL | 5 | 09-01-2008 04:40 AM |
| How to get this o/p from the sql query | bhaski | SQL | 4 | 06-21-2008 02:27 AM |
| What is an Ad Hoc Query | Lokesh M | Data Warehousing | 0 | 01-31-2008 06:57 AM |
| DB2 query | kanchhana | DB2 | 2 | 12-28-2007 01:12 AM |
| SQL Query | vidyasris | SQL | 2 | 09-24-2007 08:24 AM |