user2804097
user2804097

Reputation: 35

SQL Help(Date Functions)

I need help on SQL Queries. TABLE:

Create Table Employees
        ( employee_id   number(3) Primary Key,
          first_name    varchar2(10),
          last_name varchar2(10),
          dept_code varchar2(3),
          hire_date date,
          credit_limit  number(4,2),
          phone_ext varchar2(4),
          manager_id    number(3)
        );

Entries:

insert into Employees values (201, 'Susan', 'Brown', 'Exe', To_Date('01-Jun-1998','DD-Mon-YYYY'), 30, '3484', null);
insert into Employees values (202, 'Jim', 'Kern', 'Sal', To_Date('16-Aug-1999','DD-Mon-YYYY'), 25, '8722', 201);
insert into Employees values (203, 'Martha', 'Woods', 'Shp', To_Date('02-Feb-2004','DD-Mon-YYYY'), 25, '7591', 201);    
insert into Employees values (204, 'Ellen', 'Owens', 'Sal', To_Date('01-Jul-2003','DD-Mon-YYYY'), 15, '6830', 202);

I need a query to List all the employees, their hire dates and the number of days each person will have worked for the company as of January 1, 2007.

Upvotes: 1

Views: 43

Answers (1)

gengisdave
gengisdave

Reputation: 2050

You can use YEAR() on a date field:

SELECT * FROM Employees WHERE YEAR(hire_date)='2003'

if it doesn't work, you can use EXTRACT():

SELECT * FROM Employees WHERE EXTRACT(YEAR FROM hire_date)='2003'

and, as Alan Hadsell rightly commented:

SELECT COUNT(*) FROM Employees WHERE EXTRACT(YEAR FROM hire_date)='2003'

Upvotes: 1

Related Questions