-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingle Row Function(2).sql
More file actions
63 lines (53 loc) · 1.68 KB
/
Copy pathSingle Row Function(2).sql
File metadata and controls
63 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Single Row Function part(2)
-- By Awais Manzoor
-- Question No : 01
-- Display the last name and the number of weeks employed for all employees in department 90.
SELECT
last_name,
ROUND((SYSDATE - hire_date)/7, 1) AS weeks_employed
FROM
employees
WHERE
department_id = 90;
-- Question No : 02
-- Display employee number, hire date, number of months employed, six-month review date, first Friday after hire date
-- and the last day of the hire month for all employees who have been employed for fewer than 150 months.
SELECT
employee_id,
hire_date,
MONTHS_BETWEEN(SYSDATE, hire_date) AS months_employed,
ADD_MONTHS(hire_date, 6) AS review_date,
NEXT_DAY(hire_date, 'FRIDAY') AS first_friday,
LAST_DAY(hire_date) AS end_of_month
FROM
employees
WHERE
MONTHS_BETWEEN(SYSDATE, hire_date) < 150;
-- Question No : 03
-- For all employees who started in 1997, display the employee number, hire date, and starting month using the ROUND and TRUNC functions.
SELECT
employee_id,
hire_date,
ROUND(hire_date, 'MONTH') AS rounded_month,
TRUNC(hire_date, 'MONTH') AS truncated_month
FROM
employees
WHERE
TO_CHAR(hire_date, 'YYYY') = '1997';
-- Question No : 04
-- Use TO_CHAR to convert a datetime data type to a value of VARCHAR2 data type.
SELECT
employee_id,
TO_CHAR(hire_date, 'DD-Mon-YYYY') AS formatted_hire_date
FROM
employees;
-- -- Question No : 05
-- Display employees hired before 1990, using the RR date format.
SELECT
employee_id,
last_name,
hire_date
FROM
employees
WHERE
hire_date < TO_DATE('01-JAN-90', 'DD-MON-RR');