Prepare for your Next Interview
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 ...
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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- |
|
|||
|
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 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |