Geeks Talk

Prepare for your Next Interview




Retrieve data from emp table

This is a discussion on Retrieve data from emp table within the SQL forums, part of the Databases category; Hi All, Can anybody help me in solving this simple query. I have one emp table where empname and hiredate are few columns. I want to retrieve in which year ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-08-2007
Junior Member
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Sampurna is on a distinguished road
Retrieve data from emp table

Hi All,

Can anybody help me in solving this simple query.
I have one emp table where empname and hiredate are few columns.
I want to retrieve in which year most of the employess are joined.
So in my table in the year 1981 more employess are joined.
Can anybody help how to extract this year.

Regards

Sampurna
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-09-2007
Expert Member
 
Join Date: Dec 2006
Location: Chennai
Posts: 197
Thanks: 2
Thanked 16 Times in 14 Posts
Barbie is on a distinguished road
Re: Retrieve data from emp table

select to_char(hiredate,YYYY),max(count(to_char(hiredate,YYYY)))
from emp
groupby to_char(hiredate,YYYY),;

This will retrieves the year in which maximum employees joined and how many joined in that year.
Reply With Quote
  #3 (permalink)  
Old 05-10-2007
Contributing Member
 
Join Date: Apr 2007
Location: bangalore
Posts: 46
Thanks: 0
Thanked 9 Times in 9 Posts
reetasharma108 is on a distinguished road
Re: Retrieve data from emp table

Hi,

Try this:-

select hire_dt,emp_name from (select rownum rw, emp_name,hire_dt from(select * from emp order by hire_dt desc)) where rw =&n;

here u will give value of n as position u want.eg.
first highest year have n=1,
sec will have n=2,
third n=3 and so on...........

select hire_dt,emp_name from (select rownum rw, emp_name,hire_dt from(select * from emp order by hire_dt desc)) where rw =1;

Thanks
Reeta
Reply With Quote
  #4 (permalink)  
Old 05-11-2007
Expert Member
 
Join Date: Nov 2006
Location: Hyd-IND
Posts: 512
Thanks: 1
Thanked 53 Times in 45 Posts
sutnarcha is on a distinguished road
Re: Retrieve data from emp table

This WILL work

SELECT TOP 1 Count(*) AS C1, Year(hiredate) AS C2 FROM emp GROUP BY Year(hiredate) ORDER BY C1 DESC;
__________________
Lack of WILL POWER has caused more failure than
lack of INTELLIGENCE or ABILITY.

-sutnarcha-
Reply With Quote
  #5 (permalink)  
Old 08-13-2008
Junior Member
 
Join Date: Aug 2008
Location: Chennai
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
srivarisasi is on a distinguished road
Re: Retrieve data from emp table

Hi
try this query

select to_char(hiredate,'yyyy') from emp group by to_char(hiredate,'yyyy') having count(to_char(hiredate,'yyyy'))= (select max(count(*)) from emp group by to_char(hiredate,'yy'));

Regards
Sasikumar
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
DML for a table? Lokesh M Data Warehousing 3 04-25-2007 07:53 AM
Get the data into data file while uploading JobHelper Oracle Apps 1 03-03-2007 10:38 PM
Retrieve arguments passed to all running exes JobHelper C# 0 12-19-2006 03:42 AM
Help me retrieve my password joel MY SQL 1 12-19-2006 02:53 AM
Retrieve a pdf document from database Lokesh M Database General 5 12-18-2006 08:44 AM


All times are GMT -4. The time now is 12:23 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved