0% found this document useful (0 votes)
4 views3 pages

Pre Rdbms

The document outlines the creation of four database tables: Employees, Department, Orders, and Customer, along with their respective fields and data types. It includes sample data insertion for each table and various SQL queries to retrieve specific information, such as employees earning above average salary, employees without managers, and departments with no employees. Additionally, it provides queries to find the second-highest salary and employees hired before a certain date.

Uploaded by

dogipab706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Pre Rdbms

The document outlines the creation of four database tables: Employees, Department, Orders, and Customer, along with their respective fields and data types. It includes sample data insertion for each table and various SQL queries to retrieve specific information, such as employees earning above average salary, employees without managers, and departments with no employees. Additionally, it provides queries to find the second-highest salary and employees hired before a certain date.

Uploaded by

dogipab706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

create table Employees (

employee_id number primary key,


name varchar(50),
salary varchar(12),
department_id number,
manager_id number,
hire_date date
)

create table Department(


department_id number primary key,
department_name varchar(15)
)

create table orders(


order_id number primary key,
customer_id number,
order_date date,
total_amount number(10,2) )

create table customer(


customer_id number primary key,
customer_name varchar(100) )

desc employees

INSERT INTO Employees VALUES (101, 'Alice', 60000, 1, NULL, TO_DATE('2018-06-15',


'YYYY-MM-DD'));
INSERT INTO Employees VALUES (102, 'Bob', 75000, 2, 101, TO_DATE('2017-08-10',
'YYYY-MM-DD'));
INSERT INTO Employees VALUES (103, 'Charlie', 50000, 1, 101, TO_DATE('2019-04-20',
'YYYY-MM-DD'));
INSERT INTO Employees VALUES (104, 'David', 90000, 2, 102, TO_DATE('2016-12-05',
'YYYY-MM-DD'));
INSERT INTO Employees VALUES (105, 'Eve', 70000, 3, 104, TO_DATE('2020-01-25',
'YYYY-MM-DD'));

select *from employees

desc department

INSERT INTO Department VALUES (1, 'HR');


INSERT INTO Department VALUES (2, 'IT');
INSERT INTO Department VALUES (3, 'Finance');

select *from department

desc customer

INSERT INTO Customer VALUES (1, 'John Doe');


INSERT INTO Customer VALUES (2, 'Jane Smith');
select *from customer

desc orders

INSERT INTO Orders VALUES (1001, 1, TO_DATE('2024-03-10', 'YYYY-MM-DD'), 250.50);


INSERT INTO Orders VALUES (1002, 2, TO_DATE('2024-03-12', 'YYYY-MM-DD'), 100.75);

select *from orders

query: find employees who earn more than the average salary

select *from employees


where salary > (
select avg(salary) from employees)

query: find employees who work in the same department as alice.

select department_id from employees where name = 'Alice'

select *from employees where department_id = (select department_id from


employees where name = 'Alice')

select *from employees


select *from department
select *from customer
select *from orders

query: find employees who do not have a manager

select *from employees


where manager_id is null

query: find department that have no employees

select *from department


where department_id not in (select distinct department_id from employees)

query: the second-highest salary in the company

select max(salary) as second_salary from employees


where salary < (select max(salary) from employees)

select *from employees


where hire_date < To_Date('2019-01-01', 'yyyy-mm-dd')

select *from employees


where department_id = (select department_id from department where department_name
= 'IT')

select *from department


where department_id = ( select department_id from employees where name =

You might also like