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

Dbms Lab1

The document contains SQL queries and results from multiple tables in a database. It selects data from tables like Employee, Bank, Works, Customer, Item, Sales, etc and joins some tables to find relationships between columns. Some queries aggregate data using functions like count, sum, avg and group by. It also uses subqueries and comparisons to filter rows based on conditions.

Uploaded by

dpaul.code
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Dbms Lab1

The document contains SQL queries and results from multiple tables in a database. It selects data from tables like Employee, Bank, Works, Customer, Item, Sales, etc and joins some tables to find relationships between columns. Some queries aggregate data using functions like count, sum, avg and group by. It also uses subqueries and comparisons to filter rows based on conditions.

Uploaded by

dpaul.code
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

mysql> select * from Employee;

+---------------+-----------+---------+
| employee_name | street | city |
+---------------+-----------+---------+
| Satish | Thuvakudi | Trichy |
| Charan | Thuvakudi | Trichy |
| Harsha | Andheri | Mumbai |
| Dishant | Andheri | Mumbai |
| Aquib | Andheri | Mumbai |
| Nishant | Egmore | Chennai |
| Pushpendra | Egmore | Chennai |
| Raghuveer | Andheri | Mumbai |
| Souradeep | Andheri | Mumbai |
| Shriram | Egmore | Chennai |
| Shashank | Egmore | Chennai |
+---------------+-----------+---------+

mysql> select * from Bank;


+----------------+----------+
| bank_name | city |
+----------------+----------+
| SBI | Chennai |
| Bank_of_Baroda | Mumbai |
| PNB | Amritsar |
| Bank of Oman | Trichy |
+----------------+----------+

mysql> select * from Works;


+---------------+----------------+--------+
| employee_name | bank_name | salary |
+---------------+----------------+--------+
| Satish | SBI | 20000 |
| Charan | SBI | 30000 |
| Harsha | Bank_of_Baroda | 40000 |
| Dishant | PNB | 50000 |
| Aquib | Bank_of_Oman | 60000 |
| Nishant | SBI | 40000 |
| Pushpendra | SBI | 50000 |
| Raghuveer | Bank_of_Oman | 120000 |
| Souradeep | Bank_of_Baroda | 80000 |
| Shriram | SBI | 80000 |
+---------------+----------------+--------+

mysql> select * from Manages;


+---------------+--------------+
| employee_name | manager_name |
+---------------+--------------+
| Satish | Souradeep |
| Charan | Souradeep |
| Harsha | Raghuveer |
| Dishant | Harsha |
| Aquib | Raghuveer |
| Nishant | Shriram |
| Pushpendra | Shriram |
| Raghuveer | |
| Souradeep | Raghuveer |
| Shriram | Raghuveer |
+---------------+--------------+
mysql> select E.employee_name,street,city from Employee E,Works W where
W.bank_name='Bank_of_Oman' and E.employee_name=W.employee_name;
+---------------+---------+--------+
| employee_name | street | city |
+---------------+---------+--------+
| Aquib | Andheri | Mumbai |
| Raghuveer | Andheri | Mumbai |
+---------------+---------+--------+

mysql> select E.employee_name,street,city from Employee E,Works W where


W.bank_name='Bank_of_Oman' and Salary>41000 and E.employee_name=W.employee_name;
+---------------+---------+--------+
| employee_name | street | city |
+---------------+---------+--------+
| Aquib | Andheri | Mumbai |
| Raghuveer | Andheri | Mumbai |
+---------------+---------+--------+

mysql> select E.employee_name from Employee E,Works W,Bank B where E.city=B.city


and E.employee_name=W.employee_name and W.bank_name=B.bank_name;
+---------------+
| employee_name |
+---------------+
| Nishant |
| Pushpendra |
| Shriram |
| Harsha |
| Souradeep |
+---------------+

mysql> select p.employee_name from Employee p,Employee r,Manages m where


p.employee_name=m.employee_name and m.manager_name=r.employee_name and
p.street=r.street and p.city=r.city;
+---------------+
| employee_name |
+---------------+
| Harsha |
| Dishant |
| Aquib |
| Nishant |
| Pushpendra |
| Souradeep |
+---------------+

mysql> select W.employee_name from Works W where bank_name<>'SBI';


+---------------+
| employee_name |
+---------------+
| Harsha |
| Dishant |
| Aquib |
| Raghuveer |
| Souradeep |
+---------------+

mysql> select W.employee_name from Works W where salary>(select Max(W.salary) from


Works W where bank_name='Bank_of_Baroda');
+---------------+
| employee_name |
+---------------+
| Raghuveer |
+---------------+

mysql> select employee_name from Works t where salary >(select avg(salary) from
Works s where t.bank_name=s.bank_name);
+---------------+
| employee_name |
+---------------+
| Pushpendra |
| Raghuveer |
| Souradeep |
| Shriram |
+---------------+

mysql> select bank_name from Works group by bank_name having count(distinct


employee_name) >= all(select count(distinct employee_name) from Works group by
bank_name);
+-----------+
| bank_name |
+-----------+
| SBI |
+-----------+

mysql> select bank_name from Works group by bank_name having sum(salary)<=all


(select sum(salary) from Works group by bank_name);
+-----------+
| bank_name |
+-----------+
| PNB |
+-----------+

mysql> select employee_name from Works where salary > (select avg(salary) from
Works where bank_name='SBI');
+---------------+
| employee_name |
+---------------+
| Dishant |
| Aquib |
| Pushpendra |
| Raghuveer |
| Souradeep |
| Shriram |
+---------------+

mysql> select bank_name ,count(distinct employee_name) from Works group by


bank_name;
+----------------+-------------------------------+
| bank_name | count(distinct employee_name) |
+----------------+-------------------------------+
| Bank_of_Baroda | 2 |
| Bank_of_Oman | 2 |
| PNB | 1 |
| SBI | 5 |
+----------------+-------------------------------+

mysql> select * from Customer;


+---------+------------+
| cust_id | cust_name |
+---------+------------+
| 1 | Veer |
| 2 | Wasim |
| 3 | Kangkan |
| 4 | Souradeep |
| 5 | Anshul |
| 6 | Vivek |
| 7 | Pushpendra |
| 8 | Prajyot |
| 9 | Mahadevan |
| 10 | Madhan |
+---------+------------+
10 rows in set (0.00 sec)

mysql> select * from Item;


+----------+-----------+-------+
| item_num | item_name | price |
+----------+-----------+-------+
| 101 | Pen | 5 |
| 102 | Pencil | 6 |
| 103 | Notebook | 20 |
| 104 | Mobile | 10000 |
| 105 | Charger | 200 |
| 106 | Earphone | 500 |
| 107 | Cap | 100 |
| 108 | Keyring | 30 |
| 109 | Shirt | 100 |
| 110 | Pant | 1000 |
+----------+-----------+-------+
10 rows in set (0.00 sec)

mysql> select * from Sales;


+----------+------------+---------+---------+---------------+
| bill_num | bill_data | cust_id | item_id | quantity_sold |
+----------+------------+---------+---------+---------------+
| 1001 | 2019-01-20 | 1 | 101 | 25 |
| 1002 | 2019-01-21 | 2 | 105 | 7 |
| 1003 | 2019-01-25 | 3 | 106 | 4 |
| 1004 | 2019-01-27 | 3 | 108 | 3 |
| 1005 | 2019-01-23 | 4 | 109 | 7 |
| 1006 | 2019-01-28 | 7 | 103 | 2 |
| 1007 | 2019-01-29 | 6 | 110 | 5 |
| 1008 | 2019-01-30 | 5 | 102 | 6 |
| 1009 | 2019-01-31 | 9 | 104 | 8 |
| 1010 | 2019-01-31 | 10 | 110 | 4 |
| 101 | 2019-02-07 | 5 | 103 | 9 |
+----------+------------+---------+---------+---------------+

mysql> select cust_name,item_id from Customer,Sales where bill_data='20190131' and


Customer.cust_id =Sales.cust_id;
+-----------+---------+
| cust_name | item_id |
+-----------+---------+
| Mahadevan | 104 |
| Madhan | 110 |
+-----------+---------+
2 rows in set (0.31 sec)
mysql> select c.cust_id,cust_name,item_num,item_name,price from Customer c,Item
i,Sales s where c.cust_id=s.cust_id and i.item_num=s.item_id and price>200;
+---------+-----------+----------+-----------+-------+
| cust_id | cust_name | item_num | item_name | price |
+---------+-----------+----------+-----------+-------+
| 3 | Kangkan | 106 | Earphone | 500 |
| 6 | Vivek | 110 | Pant | 1000 |
| 9 | Mahadevan | 104 | Mobile | 10000 |
| 10 | Madhan | 110 | Pant | 1000 |
+---------+-----------+----------+-----------+-------+
4 rows in set (0.00 sec)

mysql> select s.cust_id,count(item_id) from Customer c,Sales s where


c.cust_id=s.cust_id group by s.cust_id;
+---------+----------------+
| cust_id | count(item_id) |
+---------+----------------+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 1 |
| 5 | 2 |
| 6 | 1 |
| 7 | 1 |
| 9 | 1 |
| 10 | 1 |
+---------+----------------+
9 rows in set (0.00 sec)

mysql> select item_num,item_name from Item,Sales where cust_id =5 and


Item.item_num=Sales.item_id;
+----------+-----------+
| item_num | item_name |
+----------+-----------+
| 102 | Pencil |
| 103 | Notebook |
+----------+-----------+
2 rows in set (0.00 sec)

mysql> select item_num,item_name from Item,Sales where bill_data='20190207' and


Item.item_num=Sales.item_id;
+----------+-----------+
| item_num | item_name |
+----------+-----------+
| 103 | Notebook |
+----------+-----------+

mysql> select * from Employee1;


+--------+-----------+
| emp_id | emp_name |
+--------+-----------+
| 1 | Aamod |
| 2 | Abhishek |
| 3 | Aditi |
| 4 | Akansha |
| 5 | Ankita |
| 6 | Anuradha |
| 7 | Ashutosh |
| 8 | Chirayu |
| 9 | Divya |
| 10 | Komal |
| 11 | Mohnish |
| 12 | Nupur |
| 13 | Riya |
| 14 | Sapna |
| 15 | Shreya |
| 16 | Shreyansh |
| 17 | Swati |
| 18 | Tripti |
| 19 | Vikram |
| 20 | Akshay |
+--------+-----------+
20 rows in set (0.00 sec)

mysql> select * from Dept1;


+---------+-------+
| dept_id | name |
+---------+-------+
| 101 | Civil |
| 102 | CSE |
| 103 | EE |
| 104 | EEE |
| 105 | ETC |
| 106 | IT |
| 107 | Mech |
+---------+-------+
7 rows in set (0.07 sec)

mysql> select * from Paydetails1;


+--------+---------+-----------+------------+------------+------------+
| emp_id | dept_id | basic_pay | deductions | allowances | DOJ |
+--------+---------+-----------+------------+------------+------------+
| 1 | 107 | 8000 | 4000 | 5000 | 2019-02-01 |
| 2 | 106 | 9000 | 5000 | 3000 | 2019-02-02 |
| 3 | 105 | 6000 | 4000 | 2000 | 2019-02-03 |
| 4 | 104 | 10000 | 4000 | 6000 | 2019-02-03 |
| 5 | 103 | 18000 | 2000 | 4000 | 2019-02-04 |
| 6 | 102 | 20000 | 2000 | 4000 | 2019-02-04 |
| 7 | 101 | 5000 | 4000 | 2000 | 2019-02-05 |
| 8 | 107 | 15000 | 4000 | 3000 | 2019-02-05 |
| 9 | 106 | 13000 | 6000 | 6000 | 2019-02-06 |
| 10 | 106 | 14000 | 7000 | 3000 | 2019-02-06 |
| 11 | 105 | 13000 | 8000 | 4000 | 2019-02-07 |
| 12 | 104 | 16000 | 8000 | 5000 | 2019-02-07 |
| 13 | 103 | 12000 | 6000 | 2000 | 2019-02-08 |
| 14 | 102 | 4000 | 500 | 1000 | 2019-02-08 |
| 15 | 101 | 9000 | 1500 | 2000 | 2019-02-09 |
| 16 | 107 | 10000 | 400 | 2000 | 2019-02-09 |
| 17 | 106 | 12000 | 1400 | 2000 | 2019-02-10 |
| 18 | 105 | 7000 | 1400 | 2000 | 2019-02-11 |
| 19 | 104 | 17000 | 2300 | 7000 | 2019-02-12 |
| 20 | 103 | 15000 | 6400 | 4000 | 2019-02-12 |
+--------+---------+-----------+------------+------------+------------+
20 rows in set (0.00 sec)
mysql> select * from Payroll1;
+--------+------------+
| emp_id | pay_date |
+--------+------------+
| 1 | 2019-02-01 |
| 2 | 2019-02-02 |
| 3 | 2019-02-03 |
| 4 | 2019-02-04 |
| 5 | 2019-02-05 |
| 6 | 2019-02-06 |
| 7 | 2019-02-07 |
| 8 | 2019-02-08 |
| 9 | 2019-02-09 |
| 10 | 2019-02-10 |
| 11 | 2019-02-01 |
| 12 | 2019-02-02 |
| 13 | 2019-02-03 |
| 14 | 2019-02-04 |
| 15 | 2019-02-05 |
| 16 | 2019-02-06 |
| 17 | 2019-02-07 |
| 18 | 2019-02-08 |
| 19 | 2019-02-09 |
| 20 | 2019-02-10 |
+--------+------------+
20 rows in set (0.01 sec)

mysql> select * from Employee1 e,Paydetails1 p where e.emp_id=p.emp_id order by


Dept_id;
+--------+-----------+--------+---------+-----------+------------+------------
+------------+
| emp_id | emp_name | emp_id | dept_id | basic_pay | deductions | allowances | DOJ
|
+--------+-----------+--------+---------+-----------+------------+------------
+------------+
| 15 | Shreya | 15 | 101 | 9000 | 1500 | 2000 |
2019-02-09 |
| 7 | Ashutosh | 7 | 101 | 5000 | 4000 | 2000 |
2019-02-05 |
| 14 | Sapna | 14 | 102 | 4000 | 500 | 1000 |
2019-02-08 |
| 6 | Anuradha | 6 | 102 | 20000 | 2000 | 4000 |
2019-02-04 |
| 13 | Riya | 13 | 103 | 12000 | 6000 | 2000 |
2019-02-08 |
| 5 | Ankita | 5 | 103 | 18000 | 2000 | 4000 |
2019-02-04 |
| 20 | Akshay | 20 | 103 | 15000 | 6400 | 4000 |
2019-02-12 |
| 4 | Akansha | 4 | 104 | 10000 | 4000 | 6000 |
2019-02-03 |
| 19 | Vikram | 19 | 104 | 17000 | 2300 | 7000 |
2019-02-12 |
| 12 | Nupur | 12 | 104 | 16000 | 8000 | 5000 |
2019-02-07 |
| 18 | Tripti | 18 | 105 | 7000 | 1400 | 2000 |
2019-02-11 |
| 11 | Mohnish | 11 | 105 | 13000 | 8000 | 4000 |
2019-02-07 |
| 3 | Aditi | 3 | 105 | 6000 | 4000 | 2000 |
2019-02-03 |
| 9 | Divya | 9 | 106 | 13000 | 6000 | 6000 |
2019-02-06 |
| 10 | Komal | 10 | 106 | 14000 | 7000 | 3000 |
2019-02-06 |
| 2 | Abhishek | 2 | 106 | 9000 | 5000 | 3000 |
2019-02-02 |
| 17 | Swati | 17 | 106 | 12000 | 1400 | 2000 |
2019-02-10 |
| 1 | Aamod | 1 | 107 | 8000 | 4000 | 5000 |
2019-02-01 |
| 16 | Shreyansh | 16 | 107 | 10000 | 400 | 2000 |
2019-02-09 |
| 8 | Chirayu | 8 | 107 | 15000 | 4000 | 3000 |
2019-02-05 |
+--------+-----------+--------+---------+-----------+------------+------------
+------------+

mysql> select * from Employee1 e,Paydetails1 p where p.basic_pay>=10000 and


p.basic_pay<=20000 and e.emp_id=p.emp_id;
+--------+-----------+--------+---------+-----------+------------+------------
+------------+
| emp_id | emp_name | emp_id | dept_id | basic_pay | deductions | allowances | DOJ
|
+--------+-----------+--------+---------+-----------+------------+------------
+------------+
| 4 | Akansha | 4 | 104 | 10000 | 4000 | 6000 |
2019-02-03 |
| 5 | Ankita | 5 | 103 | 18000 | 2000 | 4000 |
2019-02-04 |
| 6 | Anuradha | 6 | 102 | 20000 | 2000 | 4000 |
2019-02-04 |
| 8 | Chirayu | 8 | 107 | 15000 | 4000 | 3000 |
2019-02-05 |
| 9 | Divya | 9 | 106 | 13000 | 6000 | 6000 |
2019-02-06 |
| 10 | Komal | 10 | 106 | 14000 | 7000 | 3000 |
2019-02-06 |
| 11 | Mohnish | 11 | 105 | 13000 | 8000 | 4000 |
2019-02-07 |
| 12 | Nupur | 12 | 104 | 16000 | 8000 | 5000 |
2019-02-07 |
| 13 | Riya | 13 | 103 | 12000 | 6000 | 2000 |
2019-02-08 |
| 16 | Shreyansh | 16 | 107 | 10000 | 400 | 2000 |
2019-02-09 |
| 17 | Swati | 17 | 106 | 12000 | 1400 | 2000 |
2019-02-10 |
| 19 | Vikram | 19 | 104 | 17000 | 2300 | 7000 |
2019-02-12 |
| 20 | Akshay | 20 | 103 | 15000 | 6400 | 4000 |
2019-02-12 |
+--------+-----------+--------+---------+-----------+------------+------------
+------------+

mysql> select Dept1.dept_id,name,count(emp_id) from Dept1,Paydetails1 where


Dept1.dept_id=Paydetails1.dept_id group by Paydetails1.dept_id;
+---------+-------+---------------+
| dept_id | name | count(emp_id) |
+---------+-------+---------------+
| 101 | Civil | 2 |
| 102 | CSE | 2 |
| 103 | EE | 3 |
| 104 | EEE | 3 |
| 105 | ETC | 3 |
| 106 | IT | 4 |
| 107 | Mech | 3 |
+---------+-------+---------------+

mysql> select Employee1.emp_id,Employee1.emp_name from Employee1,Paydetails1 where


Employee1.emp_id=Paydetails1.emp_id and (basic_pay-deductions+allowances)>10000;
+--------+-----------+
| emp_id | emp_name |
+--------+-----------+
| 4 | Akansha |
| 5 | Ankita |
| 6 | Anuradha |
| 8 | Chirayu |
| 9 | Divya |
| 12 | Nupur |
| 16 | Shreyansh |
| 17 | Swati |
| 19 | Vikram |
| 20 | Akshay |
+--------+-----------+

You might also like