Question
please any help for this SQL query *) Display employee names and dependent information. Also include those employees that dont have any dependent. *) Find
please any help for this SQL query
*) Display employee names and dependent information. Also include those employees that dont have any dependent. *) Find out the employee names and number of years worked along with their department names in descending order by number of years (up to two decimal points) worked. *) Who works in the same department in which Heng Lee works? Display first name, last name and positon. Excluce Heng Lee as part of the output. *) Which department has more employees than department 20? Display the department id and number of employee in the department. *) Which employees are working in the company shorter than amin Muhammad? Display names and hire dates. *) Find employees with maximum salary in their own department with the use of correlated subquery. *) Find employee names whose last name start either with a D or C and second last character of first name is either an e or a n. *) List pair of employee names who are having the same qualification order by qualification id
-------------------------------------------------------------------------------------------------------------------------------------
(The SQL table structure)
drop table emplevel cascade constraints;
drop table position cascade constraints;
drop table dept cascade constraints;
drop table employee cascade constraints;
drop table qualification cascade constraints;
drop table dependent cascade constraints;
CREATE TABLE emplevel
(SalaryLevel CHAR(1),
LowSalary NUMBER (6),
HighSalary NUMBER (6),
CONSTRAINT emplevel_levelno_pk PRIMARY KEY (SalaryLevel));
CREATE TABLE position
(PositionId CHAR (1),
PosDesc VARCHAR2 (10),
CONSTRAINT position_positionid_pk PRIMARY KEY (PositionId));
CREATE TABLE qualification
(QualId CHAR (1),
QualDesc VARCHAR2 (20),
CONSTRAINT qualification_qualid_pk PRIMARY KEY (QualId));
CREATE TABLE dept
(DeptId NUMBER (2),
DeptName VARCHAR2 (12) NOT NULL,
Location VARCHAR2 (20),
EmployeeId NUMBER (3),
CONSTRAINT dept_deptid_pk PRIMARY KEY (DeptId));
CREATE TABLE employee
(EmployeeId NUMBER (3),
Lname VARCHAR2 (15) CONSTRAINT employee_lname_nn NOT NULL,
Fname VARCHAR2 (15) CONSTRAINT employee_fname_nn NOT NULL,
PositionId CHAR (1),
Supervisor NUMBER (3),
HireDate DATE,
Salary NUMBER (6),
Commission NUMBER (5),
DeptId NUMBER (2) NOT NULL,
QualId CHAR (1),
CONSTRAINT employee_employeeid_pk
PRIMARY KEY (EmployeeId),
CONSTRAINT employee_positionid_fk FOREIGN KEY (PositionId)
REFERENCES position (PositionId),
CONSTRAINT employee_deptid_fk FOREIGN KEY (DeptId)
REFERENCES dept (DeptId),
CONSTRAINT employee_qualid_fk FOREIGN KEY (QualId)
REFERENCES qualification (QualId));
CREATE TABLE dependent
(EmployeeId NUMBER (3),
DependentId NUMBER (1),
DepDOB DATE,
Relation VARCHAR2 (8),
CONSTRAINT dependent_empiddepid_pk PRIMARY KEY (EmployeeId, DependentId),
CONSTRAINT dependent_employeeid_fk FOREIGN KEY (EmployeeId)
REFERENCES employee (EmployeeId));
INSERT INTO emplevel VALUES ('A', 1, 25000);
INSERT INTO emplevel VALUES ('B', 25001, 50000);
INSERT INTO emplevel VALUES ('C', 50001, 100000);
INSERT INTO emplevel VALUES ('D', 100001, 500000);
INSERT INTO position VALUES ('P', 'President');
INSERT INTO position VALUES ('M', 'Manager');
INSERT INTO position VALUES ('R', 'Programmer');
INSERT INTO position VALUES ('A', 'Accountant');
INSERT INTO position VALUES ('S', 'Salesman');
INSERT INTO qualification VALUES ('D', 'Doctorate');
INSERT INTO qualification VALUES ('M', 'Masters');
INSERT INTO qualification VALUES ('B', 'Bachelors');
INSERT INTO qualification VALUES ('H', 'Higher Diploma');
INSERT INTO qualification VALUES ('C', 'Certificate');
INSERT INTO dept VALUES (10, 'Finance', 'Kuala Lumpur', 123);
INSERT INTO dept VALUES (20, 'InfoSys', 'Cyberjaya', 443);
INSERT INTO dept VALUES (30, 'Sales', 'Subang Jaya', 135);
INSERT INTO dept VALUES (40, 'Marketing', 'Petaling Jaya', 246);
INSERT INTO employee VALUES (111, 'Lee', 'Heng', 'P', NULL,
TO_DATE ('04/15/1966', 'mm/dd/yyyy'), 265000, 35000, 10, 'D');
INSERT INTO employee VALUES (246, 'Krisna', 'Ananda', 'M', 111,
TO_DATE ('05/19/1967', 'mm/dd/yyyy'), 150000, 10000, 40, 'M');
INSERT INTO employee VALUES (231, 'Andiapan', 'Nagapan', 'A', 246,
TO_DATE ('06/13/1980', 'mm/dd/yyyy'), 85000, 8500, 40, 'B');
INSERT INTO employee VALUES (123, 'Raja', 'Vellu', 'M', 111,
TO_DATE ('12/02/1991', 'mm/dd/yyyy'), 105000, NULL, 10, 'M');
INSERT INTO employee VALUES (443, 'Ali', 'Fatimah', 'M', 111,
TO_DATE ('03/15/1995', 'mm/dd/yyyy'), 80000, 20000, 20, 'B');
INSERT INTO employee VALUES (433, 'Muhammad', 'Amin', 'R', 443,
TO_DATE ('05/10/1997', 'mm/dd/yyyy'), 66500, NULL, 20, 'H');
INSERT INTO employee VALUES (323, 'Salah', 'Kamuingat', 'R', 443,
TO_DATE ('01/01/1995', 'mm/dd/yyyy'), 76500, NULL, 20, 'B');
INSERT INTO employee VALUES (200, 'Seow', 'Jing', 'S', 135,
TO_DATE ('01/03/00', 'mm/dd/yy'), 24500, 3000, 30, NULL);
INSERT INTO employee VALUES (135, 'Chan', 'Hong', 'M', 111,
TO_DATE ('02/29/1996', 'mm/dd/yyyy'), 45000, 5000, 30, 'C');
INSERT INTO employee VALUES (322, 'Chen', 'Derek', 'A', 123,
TO_DATE ('08/15/1999', 'mm/dd/yyyy'), 75000, NULL, 10, 'B');
INSERT INTO employee VALUES (128, 'Din', 'Dong', 'R', 135,
TO_DATE ('02/29/1996', 'mm/dd/yyyy'), 38000, 8000, 30, 'C');
INSERT INTO employee VALUES (248, 'Chow', 'Fatt', 'A', 135,
TO_DATE ('08/15/1999', 'mm/dd/yyyy'), 30000, NULL, 10, 'B');
INSERT INTO dependent VALUES (443, 1, TO_DATE ('09/28/1968', 'mm/dd/yyyy'),
'Spouse');
INSERT INTO dependent VALUES (443, 2, TO_DATE ('10/14/1988', 'mm/dd/yyyy'),
'Son');
INSERT INTO dependent VALUES (200, 1, TO_DATE ('06/10/1976', 'mm/dd/yyyy'),
'Spouse');
INSERT INTO dependent VALUES (322, 1, TO_DATE ('02/04/1975', 'mm/dd/yyyy'),
'Spouse');
INSERT INTO dependent VALUES (322, 2, TO_DATE ('08/23/1997', 'mm/dd/yyyy'),
'Son');
INSERT INTO dependent VALUES (322, 3, TO_DATE ('07/10/1999', 'mm/dd/yyyy'),
'Daughter');
INSERT INTO dependent VALUES (111, 1, TO_DATE ('12/12/1965', 'mm/dd/yyyy'),
'Spouse');
ALTER TABLE dept
ADD CONSTRAINT dept_employeeid_fk FOREIGN KEY(EmployeeId)
REFERENCES employee(EmployeeId);
ALTER TABLE employee
ADD CONSTRAINT employee_supervisor_fk FOREIGN KEY(Supervisor)
REFERENCES employee(EmployeeId);
commit;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started