I want to display the employees who have joined in last two
months. (It should be executed randomly means If I execute
the query in March it should display Jan and Feb joined
employees. Same query if i execute in Feb, 2007 it should
display dec, 2006 and jan 2007 joined employees.
Answers were Sorted based on User's Feedback
Answer / sdp
select * from emp
where trunc(months_between(sysdate, hiredate))=2;
| Is This Answer Correct ? | 39 Yes | 14 No |
Answer / suneel
select * from af where months_between(sysdate,hiredate)<=2
| Is This Answer Correct ? | 16 Yes | 2 No |
Answer / raji_4u
select *
from emp
where hiredate
between add_months(trunc(sysdate,'Month'),-2)
and trunc(sysdate,'Month')-1
This works for sure. 100 %
| Is This Answer Correct ? | 14 Yes | 1 No |
Answer / avi007
select * from employee where (sysdate-hiredate) <=60
| Is This Answer Correct ? | 6 Yes | 3 No |
Answer / arijit
take Mon(like sep,oct,mar etc)
and year( like 2006,2007,1980 etc) as input...
and execute this query..
select empno,ename,hiredate from emp1
where hiredate between
add_months(to_date('01-'|| upper('&Mon')||'-'||&yr,'DD-MON-
YYYY'),-2) and last_day(add_months(to_date('01-'|| upper
('&Mon')||'-'||&yr,'DD-MON-YYYY'),-1))
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / kesava
100% sure execute
select * from emp
where hiredate between
trunc(add_months(last_day(sysdate),-3)+1) and
trunc(add_months(last_day(sysdate),-1))
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / balaji s.t
select convert(varchar(10),
dateadd(dd,-(day(dateadd(mm,1,getdate()))-1), dateadd(mm,-2,getdate())), 120),
convert(varchar(10),dateadd(dd,-(day(getdate())),getdate()),120)
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / shanmukha srinivas
1)last two months joined employees
select * from emp where hiredate between add_months(trunc(sysdate,'month'),-2) and trunc(sysdate,'month')
2)last two months joined employees from today
select * from emp where hiredate between add_months(trunc(sysdate),-2) and trunc(sysdate)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / satish
select * from emp where
round(months_between(sysdate,hire_date) in(1,2);
| Is This Answer Correct ? | 0 Yes | 1 No |
how to eliminate null values in a column i.e table vlaues 1 2 3 NULL 3 4 1 5 NULL i want output like this 1 2 3 3 4 1 5 i dnt want to use nvl is null and i dnt want replace the NULL value with any value i.e nvl(col,o);
explain about mysql and its features. : Sql dba
What is difference between joins and union?
Is sql injection illegal?
What is a left join?
What are user defined functions?
What is the difference between execution of triggers and stored procedures?
what is a composite key ? : Sql dba
Which column in the user.triggers data dictionary view shows that the trigger is a pl/sql trigger?
What are all the difference between Like and Contains ?
What are advantages of Stored Procedures?
What is a crud api?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)