0% found this document useful (0 votes)
8 views2 pages

Lab 3

The document outlines SQL commands to create a database and a table for employee records, including fields for employee details. It includes sample data insertion for various employees across different departments and queries to retrieve specific information such as salary, age, and gender. Additionally, it provides commands to calculate average salary and count employees by department.

Uploaded by

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

Lab 3

The document outlines SQL commands to create a database and a table for employee records, including fields for employee details. It includes sample data insertion for various employees across different departments and queries to retrieve specific information such as salary, age, and gender. Additionally, it provides commands to calculate average salary and count employees by department.

Uploaded by

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

LAB-3 EXERCISES

CREATE DATABASE IF NOT EXISTS employee_db;

USE employee_db;

CREATE TABLE IF NOT EXISTS employees (


employee_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
department VARCHAR(50) NOT NULL,
age INT,
gender ENUM('Male', 'Female', 'Other'),
salary INT(10),
address VARCHAR(255)
);

INSERT INTO employees (name, department, age, gender, salary, address) VALUES
('John Smith', 'HR', 30, 'Male', 50000, '123 Main St, City, State, Zip'),
('Jane Doe', 'IT', 35, 'Female', 60000, '456 Elm St, City, State, Zip'),
('Michael Johnson', 'Sales', 28, 'Male', 55000, '789 Oak St, City, State, Zip'),
('Emily Brown', 'Marketing', 32, 'Female', 52000, '101 Pine St, City, State, Zip'),
('David Jones', 'Finance', 40, 'Male', 70000, '234 Cedar St, City, State, Zip'),
('Jessica Wilson', 'HR', 33, 'Female', 58000, '567 Maple St, City, State, Zip'),
('Daniel Lee', 'IT', 29, 'Male', 65000, '890 Birch St, City, State, Zip'),
('Jennifer Martinez', 'Sales', 31, 'Female', 60000, '111 Spruce St, City, State, Zip'),
('Christopher Taylor', 'Marketing', 36, 'Male', 62000, '222 Walnut St, City, State, Zip'),
('Sarah Anderson', 'Finance', 38, 'Female', 75000, '333 Pine St, City, State, Zip'),
('Robert Wilson', 'HR', 45, 'Male', 80000, '444 Oak St, City, State, Zip'),
('Emma Garcia', 'IT', 27, 'Female', 53000, '555 Elm St, City, State, Zip'),
('William Martinez', 'Sales', 34, 'Male', 67000, '666 Maple St, City, State, Zip'),
('Sophia Thomas', 'Marketing', 29, 'Female', 54000, '777 Cedar St, City, State, Zip'),
('James Brown', 'Finance', 42, 'Male', 72000, '888 Pine St, City, State, Zip');

SELECT * FROM employees;

SELECT * FROM employees WHERE department = 'HR';

SELECT * FROM employees WHERE salary > 60000;

SELECT * FROM employees WHERE age BETWEEN 30 AND 40;

SELECT * FROM employees WHERE gender = 'Male';

SELECT * FROM employees WHERE gender = 'Female' AND department = 'Finance';

SELECT * FROM employees WHERE name LIKE 'J%';

SELECT * FROM employees ORDER BY salary DESC;

SELECT AVG(salary) AS average_salary FROM employees;

SELECT department, COUNT(*) AS employee_count FROM employees GROUP BY


department;

You might also like