You are on page 1of 4

-- Create employee table

CREATE TABLE employee (


employee_name VARCHAR(100),
employee_number INT,
job VARCHAR(100),
salary DECIMAL(10, 2),
dept INT
);

-- Inserting Sample Data


INSERT INTO employee (employee_name, employee_number, job,
salary, dept)
VALUES
('John', 1, 'Manager', 3000, 10),
('Alice', 2, 'Developer', 2500, 10),
('Bob', 3, 'Analyst', 2200, 20),
('Charlie', 4, 'Designer', 2800, 10),
('David', 5, 'Tester', 2000, 20),
('Eva', 6, 'Manager', 3200, 30);

-- 1. Query to find the names of employees in department No. 10


SELECT employee_name
FROM employee
WHERE dept = 10;
-- 2. Query to find the names of all employees in department No. 10
with a salary greater than 2000
SELECT employee_name
FROM employee
WHERE dept = 10 AND salary > 2000;

-- 3. Query to find the names of employees in department No. 10 or


department No. 20
SELECT employee_name
FROM employee
WHERE dept IN (10, 20);

-- 4. Query to find the names of employees who work in department


No. 10, 20, or 30
SELECT employee_name
FROM employee
WHERE dept IN (10, 20, 30);
-- 5. Query to find the names of all employees whose salary is
between 1000 and 3000
SELECT employee_name
FROM employee
WHERE salary BETWEEN 1000 AND 3000;

-- 6. Query to find the names of employees whose names lie between


'a' and 'd'
SELECT employee_name
FROM employee
WHERE employee_name BETWEEN ‘A’ AND ‘D’;

-- 7. Rename the table


ALTER TABLE employee
RENAME TO new_table_employee;
-- 8. Description of the table
DESCRIBE new_table_employee;

You might also like