0% found this document useful (0 votes)
4 views

Assignment 4

A MySQL table named 'Employ' was created to store employee data, including fields for ID, name, salary, address, working date, and working hours. Five employee records were inserted, and various queries were executed to retrieve counts of employees by address, total and average working hours per employee, and a filtered list of employees with total working hours greater than 20. The results show employee distribution across different cities and highlight Employee 5 as the one with the highest working hours.

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)
4 views

Assignment 4

A MySQL table named 'Employ' was created to store employee data, including fields for ID, name, salary, address, working date, and working hours. Five employee records were inserted, and various queries were executed to retrieve counts of employees by address, total and average working hours per employee, and a filtered list of employees with total working hours greater than 20. The results show employee distribution across different cities and highlight Employee 5 as the one with the highest working hours.

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 Employ (

-> e_id INT PRIMARY KEY,


-> e_name VARCHAR(255),
-> salary DECIMAL(10, 2),
-> address VARCHAR(255),
-> working_date DATE,
-> working_hours INT
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> desc Employ;


+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| e_id | int | NO | PRI | NULL | |
| e_name | varchar(255) | YES | | NULL | |
| salary | decimal(10,2) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
| working_date | date | YES | | NULL | |
| working_hours | int | YES | | NULL | |
+---------------+---------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> show tables;


+----------------------+
| Tables_in_assignment |
+----------------------+
| book |
| employ |
| employees |
+----------------------+
3 rows in set (0.00 sec)

mysql> -- Insert data for employees


mysql> INSERT INTO Employ (e_id, e_name, salary, address, working_date, working_hours)
-> VALUES
-> (1001, 'Employee 1', 5000, 'New York', '2023-09-01', 18),
-> (1002, 'Employee 2', 6000, 'Los Angeles', '2023-09-01', 9),
-> (1003, 'Employee 3', 5500, 'Chicago', '2023-09-02', 20),
-> (1004, 'Employee 4', 7000, 'San Francisco', '2023-09-02', 13),
-> (1005, 'Employee 5', 6500, 'New York', '2023-09-03', 32);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> select * from employ;


+------+------------+---------+---------------+--------------+---------------+
| e_id | e_name | salary | address | working_date | working_hours |
+------+------------+---------+---------------+--------------+---------------+
| 1001 | Employee 1 | 5000.00 | New York | 2023-09-01 | 18 |
| 1002 | Employee 2 | 6000.00 | Los Angeles | 2023-09-01 | 9 |
| 1003 | Employee 3 | 5500.00 | Chicago | 2023-09-02 | 20 |
| 1004 | Employee 4 | 7000.00 | San Francisco | 2023-09-02 | 13 |
| 1005 | Employee 5 | 6500.00 | New York | 2023-09-03 | 32 |
+------+------------+---------+---------------+--------------+---------------+
5 rows in set (0.00 sec)

mysql> SELECT address, COUNT(*) AS city_count


-> FROM Employ
-> GROUP BY address;
+---------------+------------+
| address | city_count |
+---------------+------------+
| New York | 2 |
| Los Angeles | 1 |
| Chicago | 1 |
| San Francisco | 1 |
+---------------+------------+
4 rows in set (0.00 sec)

mysql> SELECT e_name, SUM(working_hours) AS total_working_hours


-> FROM Employ
-> GROUP BY e_name;
+------------+---------------------+
| e_name | total_working_hours |
+------------+---------------------+
| Employee 1 | 18 |
| Employee 2 | 9 |
| Employee 3 | 20 |
| Employee 4 | 13 |
| Employee 5 | 32 |
+------------+---------------------+
5 rows in set (0.00 sec)

mysql> SELECT e_name, AVG(working_hours) AS average_working_hours


-> FROM Employ
-> GROUP BY e_name;
+------------+-----------------------+
| e_name | average_working_hours |
+------------+-----------------------+
| Employee 1 | 18.0000 |
| Employee 2 | 9.0000 |
| Employee 3 | 20.0000 |
| Employee 4 | 13.0000 |
| Employee 5 | 32.0000 |
+------------+-----------------------+
5 rows in set (0.00 sec)

mysql> SELECT e_name, SUM(working_hours) AS total_working_hours


-> FROM Employ
-> GROUP BY e_name
-> HAVING total_working_hours > 20;
+------------+---------------------+
| e_name | total_working_hours |
+------------+---------------------+
| Employee 5 | 32 |
+------------+---------------------+
1 row in set (0.00 sec)

You might also like