You are on page 1of 6

CSE3A_80_ASSGN03

mysql> use cse3A;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> use cse3A;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_cse3A |
+-----------------+
| department |
| employee |
+-----------------+
2 rows in set (0.00 sec)

mysql> show columns from employee;


+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| emp_id | int(11) | NO | PRI | NULL | |
| f_name | varchar(20) | NO | | NULL | |
| l_name | varchar(20) | YES | | NULL | |
| job_type | varchar(20) | YES | | NULL | |
| salary | int(11) | NO | | NULL | |
| commission | int(11) | YES | | NULL | |
| dept | varchar(20) | YES | | NULL | |
| manager_id | int(11) | YES | | NULL | |
| date_of_joining | date | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

mysql> select f_name,l_name,job_type from employee;


+---------+--------+------------+
| f_name | l_name | job_type |
+---------+--------+------------+
| Arun | Khan | Manager |
| Barun | Kumar | Manager |
| Chitra | Kapoor | Engineer |
| Dheeraj | Mishra | Manager |
| Emma | Dutt | Engineer |
| Floki | Dutt | Accountant |
| Dheeraj | Kumar | Clerk |
| Saul | Deol | Engineer |
| Mou | Bhat | Clerk |
| Sunny | Deol | Salesman |
| Bobby | Deol | Engineer |
| Aamir | Khan | Salesman |
+---------+--------+------------+
12 rows in set (0.00 sec)

mysql> select concat(f_name,' is a ',job_type) as 'Employee details' from employee;


+-----------------------+
| Employee details |
+-----------------------+
| Arun is a Manager |
| Barun is a Manager |
| Chitra is a Engineer |
| Dheeraj is a Manager |
| Emma is a Engineer |
| Floki is a Accountant |
| Dheeraj is a Clerk |
| Saul is a Engineer |
| Mou is a Clerk |
| Sunny is a Salesman |
| Bobby is a Engineer |
| Aamir is a Salesman |
+-----------------------+
12 rows in set (0.00 sec)

mysql> select concat(f_name,"'s monthly salary is Rs. ",salary) as 'Monthly Salary Details' from
employee;
+---------------------------------------+
| Monthly Salary Details |
+---------------------------------------+
| Arun's monthly salary is Rs. 90000 |
| Barun's monthly salary is Rs. 80000 |
| Chitra's monthly salary is Rs. 60000 |
| Dheeraj's monthly salary is Rs. 75000 |
| Emma's monthly salary is Rs. 55000 |
| Floki's monthly salary is Rs. 70000 |
| Dheeraj's monthly salary is Rs. 40000 |
| Saul's monthly salary is Rs. 60000 |
| Mou's monthly salary is Rs. 30000 |
| Sunny's monthly salary is Rs. 20000 |
| Bobby's monthly salary is Rs. 35000 |
| Aamir's monthly salary is Rs. 15000 |
+---------------------------------------+
12 rows in set (0.00 sec)

mysql> select d_name from department;


+------------+
| d_name |
+------------+
| Accounts |
| Marketing |
| Production |
|R&D |
| Sales |
+------------+
5 rows in set (0.00 sec)
mysql> select f_name as 'First Name',l_name as 'Last Name' from employee where dept='Sales';
+------------+-----------+
| First Name | Last Name |
+------------+-----------+
| Dheeraj | Mishra |
| Mou | Bhat |
+------------+-----------+
2 rows in set (0.00 sec)

mysql> select f_name as 'First Name',l_name as 'Last Name' from employee where salary>=50000;
+------------+-----------+
| First Name | Last Name |
+------------+-----------+
| Arun | Khan |
| Barun | Kumar |
| Chitra | Kapoor |
| Dheeraj | Mishra |
| Emma | Dutt |
| Floki | Dutt |
| Saul | Deol |
+------------+-----------+
7 rows in set (0.00 sec)

mysql> select * from employee where manager_id <> 1;


+--------+---------+--------+----------+--------+------------+-----------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id | date_of_joining
|
+--------+---------+--------+----------+--------+------------+-----------+------------+-----------------+
| 4 | Dheeraj | Mishra | Manager | 75000 | NULL | Sales | 4 | 2001-12-27 |
| 7 | Dheeraj | Kumar | Clerk | 40000 | NULL | Accounts | 6 | 2016-07-01 |
| 9 | Mou | Bhat | Clerk | 30000 | NULL | Sales | 4 | 2018-03-08 |
| 10 | Sunny | Deol | Salesman | 20000 | 10000 | Marketing | 2 | 2001-03-31 |
| 11 | Bobby | Deol | Engineer | 35000 | NULL | R & D | 8 | 2017-10-17 |
| 12 | Aamir | Khan | Salesman | 15000 | 5000 | Marketing | 2 | 2013-01-11 |
+--------+---------+--------+----------+--------+------------+-----------+------------+-----------------+
6 rows in set (0.06 sec)

mysql> select * from employee where salary>=40000 and salary<=70000;


+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id |
date_of_joining |
+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
| 3 | Chitra | Kapoor | Engineer | 60000 | NULL | Production | 1 | 1998-01-08 |
| 5 | Emma | Dutt | Engineer | 55000 | NULL | Production | 1 | 2002-03-20 |
| 6 | Floki | Dutt | Accountant | 70000 | NULL | Accounts | NULL | 2000-07-16 |
| 7 | Dheeraj | Kumar | Clerk | 40000 | NULL | Accounts | 6 | 2016-07-01 |
| 8 | Saul | Deol | Engineer | 60000 | NULL | R & D | NULL | 2014-08-06 |
+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
5 rows in set (0.00 sec)

mysql> select * from employee where manager_id = 1 or manager_id=6 or manager_id=8;


+--------+---------+--------+----------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id |
date_of_joining |
+--------+---------+--------+----------+--------+------------+------------+------------+-----------------+
| 3 | Chitra | Kapoor | Engineer | 60000 | NULL | Production | 1 | 1998-01-08 |
| 5 | Emma | Dutt | Engineer | 55000 | NULL | Production | 1 | 2002-03-20 |
| 7 | Dheeraj | Kumar | Clerk | 40000 | NULL | Accounts | 6 | 2016-07-01 |
| 11 | Bobby | Deol | Engineer | 35000 | NULL | R & D | 8 | 2017-10-17 |
+--------+---------+--------+----------+--------+------------+------------+------------+-----------------+
4 rows in set (0.01 sec)

mysql> select f_name,salary from employee where l_name like 'K%';


+---------+--------+
| f_name | salary |
+---------+--------+
| Arun | 90000 |
| Barun | 80000 |
| Chitra | 60000 |
| Dheeraj | 40000 |
| Aamir | 15000 |
+---------+--------+
5 rows in set (0.00 sec)

mysql> select f_name,salary from employee where l_name like 'K%r';


+---------+--------+
| f_name | salary |
+---------+--------+
| Barun | 80000 |
| Chitra | 60000 |
| Dheeraj | 40000 |
+---------+--------+
3 rows in set (0.00 sec)

mysql> select * from employee where l_name like '%o%';


+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id | date_of_joining
|
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
| 8 | Saul | Deol | Engineer | 60000 | NULL | R & D | NULL | 2014-08-06 |
| 10 | Sunny | Deol | Salesman | 20000 | 10000 | Marketing | 2 | 2001-03-31 |
| 11 | Bobby | Deol | Engineer | 35000 | NULL | R & D | 8 | 2017-10-17 |
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
4 rows in set (0.00 sec)

mysql> select * from employee where job_type = 'engineer' and salary >= 50000;
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id | date_of_joining
|
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
| 3 | Chitra | Kapoor | Engineer | 60000 | NULL | Production | 1 | 1998-01-08 |
| 5 | Emma | Dutt | Engineer | 55000 | NULL | Production | 1 | 2002-03-20 |
| 8 | Saul | Deol | Engineer | 60000 | NULL | R & D | NULL | 2014-08-06 |
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
3 rows in set (0.00 sec)
mysql> select * from employee where dept = 'Production' or salary >= 60000;
+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id |
date_of_joining |
+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
| 1 | Arun | Khan | Manager | 90000 | NULL | Production | NULL | 1998-01-04 |
| 2 | Barun | Kumar | Manager | 80000 | NULL | Marketing | NULL | 1998-02-09 |
| 3 | Chitra | Kapoor | Engineer | 60000 | NULL | Production | 1 | 1998-01-08 |
| 4 | Dheeraj | Mishra | Manager | 75000 | NULL | Sales | 4 | 2001-12-27 |
| 5 | Emma | Dutt | Engineer | 55000 | NULL | Production | 1 | 2002-03-20 |
| 6 | Floki | Dutt | Accountant | 70000 | NULL | Accounts | NULL | 2000-07-16 |
| 8 | Saul | Deol | Engineer | 60000 | NULL | R & D | NULL | 2014-08-06 |
+--------+---------+--------+------------+--------+------------+------------+------------+-----------------+
7 rows in set (0.00 sec)

mysql> select min(salary),max(salary),sum(salary),avg(salary) from employee where dept='Sales';


+-------------+-------------+-------------+-------------+
| min(salary) | max(salary) | sum(salary) | avg(salary) |
+-------------+-------------+-------------+-------------+
| 30000 | 75000 | 105000 | 52500.0000 |
+-------------+-------------+-------------+-------------+
1 row in set (0.00 sec)

mysql> select count(*) as count,department.d_name from employee inner join department on


employee.dept=department.d_name group by department.d_name;
+-------+------------+
| count | d_name |
+-------+------------+
| 2 | Accounts |
| 3 | Marketing |
| 3 | Production |
| 2|R&D |
| 2 | Sales |
+-------+------------+
5 rows in set (0.02 sec)

mysql> select count(dept) from employee;


+-------------+
| count(dept) |
+-------------+
| 12 |
+-------------+
1 row in set (0.00 sec)

mysql> select avg(commission) from employee;


+-----------------+
| avg(commission) |
+-----------------+
| 7500.0000 |
+-----------------+
1 row in set (0.00 sec)

mysql> select dept,avg(salary) from employee group by dept;


+------------+-------------+
| dept | avg(salary) |
+------------+-------------+
| Accounts | 55000.0000 |
| Marketing | 38333.3333 |
| Production | 68333.3333 |
| R & D | 47500.0000 |
| Sales | 52500.0000 |
+------------+-------------+
5 rows in set (0.00 sec)

You might also like