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

Assignment 2

A MySQL table named 'employees' was created to store employee details including ID, name, designation, and salary components. Five employees were inserted into the table, and their salary components were calculated based on their basic pay. Queries were executed to count total employees, find those with gross salaries between 5,000 and 15,000, and determine the maximum gross salary.

Uploaded by

Mrinmoy Pathak
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)
6 views2 pages

Assignment 2

A MySQL table named 'employees' was created to store employee details including ID, name, designation, and salary components. Five employees were inserted into the table, and their salary components were calculated based on their basic pay. Queries were executed to count total employees, find those with gross salaries between 5,000 and 15,000, and determine the maximum gross salary.

Uploaded by

Mrinmoy Pathak
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

mysql> CREATE TABLE employees (

-> emp_id INT AUTO_INCREMENT PRIMARY KEY,


-> emp_name VARCHAR(255),
-> designation VARCHAR(255),
-> basic_pay DECIMAL(10, 2),
-> DA DECIMAL(10, 2),
-> TA DECIMAL(10, 2),
-> HR DECIMAL(10, 2),
-> TAX DECIMAL(10, 2),
-> GROSS DECIMAL(10, 2),
-> NET DECIMAL(10, 2)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;


+----------------------+
| Tables_in_assignment |
+----------------------+
| employees |
+----------------------+
1 row in set (0.01 sec)

mysql> desc employees;


+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| emp_id | int | NO | PRI | NULL | auto_increment |
| emp_name | varchar(255) | YES | | NULL | |
| designation | varchar(255) | YES | | NULL | |
| basic_pay | decimal(10,2) | YES | | NULL | |
| DA | decimal(10,2) | YES | | NULL | |
| TA | decimal(10,2) | YES | | NULL | |
| HR | decimal(10,2) | YES | | NULL | |
| TAX | decimal(10,2) | YES | | NULL | |
| GROSS | decimal(10,2) | YES | | NULL | |
| NET | decimal(10,2) | YES | | NULL | |
+-------------+---------------+------+-----+---------+----------------+
10 rows in set (0.01 sec)

mysql> INSERT INTO employees (emp_name, designation, basic_pay)


-> VALUES
-> ('Employee 1', 'Manager', 10000),
-> ('Employee 2', 'Engineer', 8000),
-> ('Employee 3', 'Technician', 6000),
-> ('Employee 4', 'Analyst', 12000),
-> ('Employee 5', 'Clerk', 7500);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> select * from employees;


+--------+------------+-------------+-----------+------+------+------+------+-------+------+
| emp_id | emp_name | designation | basic_pay | DA | TA | HR | TAX | GROSS | NET |
+--------+------------+-------------+-----------+------+------+------+------+-------+------+
| 1 | Employee 1 | Manager | 10000.00 | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | Employee 2 | Engineer | 8000.00 | NULL | NULL | NULL | NULL | NULL | NULL |
| 3 | Employee 3 | Technician | 6000.00 | NULL | NULL | NULL | NULL | NULL | NULL |
| 4 | Employee 4 | Analyst | 12000.00 | NULL | NULL | NULL | NULL | NULL | NULL |
| 5 | Employee 5 | Clerk | 7500.00 | NULL | NULL | NULL | NULL | NULL | NULL |
+--------+------------+-------------+-----------+------+------+------+------+-------+------+
5 rows in set (0.00 sec)

mysql> UPDATE employees


-> SET
-> DA = 0.6 * basic_pay,
-> TA = 0.2 * basic_pay,
-> HR = 0.1 * basic_pay,
-> TAX = 0.15 * basic_pay,
-> GROSS = basic_pay + DA + TA + HR,
-> NET = GROSS - TAX;
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0

mysql> select * from employees;


+--------+------------+-------------+-----------+---------+---------+---------+---------+----------+----------+
| emp_id | emp_name | designation | basic_pay | DA | TA | HR | TAX | GROSS | NET |
+--------+------------+-------------+-----------+---------+---------+---------+---------+----------+----------+
| 1 | Employee 1 | Manager | 10000.00 | 6000.00 | 2000.00 | 1000.00 | 1500.00 | 19000.00 | 17500.00 |
| 2 | Employee 2 | Engineer | 8000.00 | 4800.00 | 1600.00 | 800.00 | 1200.00 | 15200.00 | 14000.00 |
| 3 | Employee 3 | Technician | 6000.00 | 3600.00 | 1200.00 | 600.00 | 900.00 | 11400.00 | 10500.00 |
| 4 | Employee 4 | Analyst | 12000.00 | 7200.00 | 2400.00 | 1200.00 | 1800.00 | 22800.00 | 21000.00 |
| 5 | Employee 5 | Clerk | 7500.00 | 4500.00 | 1500.00 | 750.00 | 1125.00 | 14250.00 | 13125.00 |
+--------+------------+-------------+-----------+---------+---------+---------+---------+----------+----------+
5 rows in set (0.00 sec)

mysql> SELECT COUNT(*) AS total_employees


-> FROM employees;
+-----------------+
| total_employees |
+-----------------+
| 5 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(*) AS employees_between_5k_and_15k


-> FROM employees
-> WHERE GROSS BETWEEN 5000 AND 15000;
+------------------------------+
| employees_between_5k_and_15k |
+------------------------------+
| 2 |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT MAX(GROSS) AS max_gross_salary


-> FROM employees;
+------------------+
| max_gross_salary |
+------------------+
| 22800.00 |
+------------------+
1 row in set (0.00 sec)

You might also like