0% found this document useful (0 votes)
11 views6 pages

Who opens this is LGBTQ++

The document outlines the creation of a MySQL database named 'Sales' with tables for Sales Representatives, Customers, and Orders, including their respective fields and relationships. It details the insertion of data into these tables and various SQL queries to retrieve and analyze the data, such as joining tables and calculating totals. The document demonstrates the use of SQL commands for database management and data retrieval in a sales context.

Uploaded by

atharvabhagat544
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)
11 views6 pages

Who opens this is LGBTQ++

The document outlines the creation of a MySQL database named 'Sales' with tables for Sales Representatives, Customers, and Orders, including their respective fields and relationships. It details the insertion of data into these tables and various SQL queries to retrieve and analyze the data, such as joining tables and calculating totals. The document demonstrates the use of SQL commands for database management and data retrieval in a sales context.

Uploaded by

atharvabhagat544
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/ 6

Assignment No.

: 3
Group : A

mysql>create database Sales; Query


OK, 1 row affected (0.16 sec)

mysql> use Sales;


Database changed

mysql> create table Sales_Representative(Rep_no int(10) PRIMARY KEY,Name


varchar(20),Re_office varchar(20),Quota varchar(20),sales varchar(20)); Query
OK, 0 rows affected, 1 warning (0.35 sec)

mysql> desc Sales_Representative;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Rep_no | int | NO | PRI | NULL | |
| Name | varchar(20) | YES | | NULL | |
| Re_office | varchar(20) | YES | | NULL | |
| Quota | varchar(20) | YES | | NULL | |
| sales | varchar(20) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.03 sec)

mysql> create table Customers(Cust_no int(10) PRIMARY KEY,Company varchar(20),Cust_Rep


int(10),Credit_Limit float(10),FOREIGN KEY (Cust_Rep) REFERENCES
Sales_Representative(Rep_no));
Query OK, 0 rows affected, 2 warnings (0.50 sec)

mysql> desc Customer;


ERROR 1146 (42S02): Table 'Sales.Customer' doesn't exist mysql>
desc Customers;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| Cust_no | int | NO | PRI | NULL | |
| Company | varchar(20) | YES | | NULL | |
| Cust_Rep | int | YES | MUL | NULL | |
| Credit_Limit | float | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> create table Orders(Order_no int(10) PRIMARY KEY,Cust int(10),Product


varchar(20),Quantity int(100),Amount float(10),Disc int(5),FOREIGN KEY (Cust) REFERENCES
Customers(Cust_no));
Query OK, 0 rows affected, 4 warnings (0.57 sec)
mysql> desc Orders;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Order_no | int | NO | PRI | NULL | |
| Cust | int | YES | MUL | NULL | |
| Product | varchar(20) | YES | | NULL | |
| Quantity | int | YES | | NULL | |
| Amount | float | YES | | NULL | |
| Disc | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into Sales_Representative values('100','Pratik','01','Marketing','13000'); Query


OK, 1 row affected (0.01 sec)
mysql> insert into Sales_Representative values('200','Tejas','02','Manufactur','14000'); Query
OK, 1 row affected (0.01 sec)
mysql> insert into Sales_Representative values('300','Kirtesh','01','Marketing','12000'); Query
OK, 1 row affected (0.01 sec)
mysql> insert into Sales_Representative values('400','Tejas','03','Marketing','10000'); Query
OK, 1 row affected (0.00 sec)

mysql> select * from Sales_Representative;


+--------+------------+-----------+------------+-------+
| Rep_no | Name | Re_office | Quota | sales |
+--------+------------+-----------+------------+-------+
| 100 | Pratik | 01 | Marketing | 13000 |
| 200 | Tejas | 02 | Manufactur | 14000 |
| 300 | Kirtesh | 01 | Marketing | 12000 |
| 400 | Tejas | 03 | Marketing | 10000 |
+--------+------------+-----------+------------+-------+
4 rows in set (0.01 sec)

mysql> insert into Customers values('1000','TCS','100','50000'); Query


OK, 1 row affected (0.00 sec)
mysql> insert into Customers values('2000','INFOSYS','200','75000'); Query
OK, 1 row affected (0.01 sec)
mysql> insert into Customers values('3000','Mahindra','300','60000'); Query
OK, 1 row affected (0.02 sec)
mysql> insert into Customers values('4000','Wipro','400','55000');
Query OK, 1 row affected (0.01 sec)
mysql> select * from Customers;
+---------+----------+----------+--------------+
| Cust_no | Company | Cust_Rep | Credit_Limit |
+---------+----------+----------+--------------+
| 1000 | TCS | 100 | 50000 |
| 2000 | INFOSYS | 200 | 75000 |
| 3000 | Mahindra | 300 | 60000 |
| 4000 | Wipro | 400 | 55000 |
+---------+----------+----------+--------------+
4 rows in set (0.01 sec)

mysql> insert into Orders values('101','1000','Laptop','50','1500000','150000'); Query


OK, 1 row affected (0.01 sec)
mysql> insert into Orders values('102','2000','PC','30','900000','90000'); Query
OK, 1 row affected (0.00 sec)
mysql> insert into Orders values('103','3000','Monitors','40','1000000','100000'); Query
OK, 1 row affected (0.01 sec)
mysql> insert into Orders values('104','4000','CPU','20','400000','40000'); Query
OK, 1 row affected (0.00 sec)

mysql> select * from Orders;


+----------+------+----------+----------+---------+--------+
| Order_no | Cust | Product | Quantity | Amount | Disc |
+----------+------+----------+----------+---------+--------+
| 101 | 1000 | Laptop | 50 | 1500000 | 150000 |
| 102 | 2000 | PC | 30 | 900000 | 90000 |
| 103 | 3000 | Monitors | 40 | 1000000 | 100000 |
| 104 | 4000 | CPU | 20 | 400000 | 40000 |
+----------+------+----------+----------+---------+--------+
4 rows in set (0.00 sec)

1.
mysql> select Customers.Company, Sales_Representative.Name, Sales_Representative.Re_office
from Customers inner join Sales_Representative on Customers.Cust_Rep =
Sales_Representative.Rep_no;
+----------+------------+-----------+
| Company | Name | Re_office |
+----------+------------+-----------+
| TCS | Pratik | 01 |
| INFOSYS | Tejas | 02 |
| Mahindra | Kirtesh | 01 |
| Wipro | Tejas | 03 |
+----------+------------+-----------+
4 rows in set (0.00 sec)
2.
mysql> select Customers.Company,Customers.Credit_Limit, Sales_Representative.Name,
Sales_Representative.sales from Customers inner join Sales_Representative on
Customers.Cust_Rep = Sales_Representative.Rep_no;
+----------+--------------+------------+-------+
| Company | Credit_Limit | Name | sales |
+----------+--------------+------------+-------+
| TCS | 50000 | Pratik | 13000 |
| INFOSYS | 75000 | Tejas | 14000 |
| Mahindra | 60000 | Kirtesh | 12000 |
| Wipro | 55000 | Tejas | 10000 |
+----------+--------------+------------+-------+
4 rows in set (0.00 sec)

3.
mysql> select Amount, Name, Company from Orders, Sales_Representative, Customers where Cust
= Cust_no AND Cust_Rep = Rep_no AND Amount>400000;
+---------+------------+----------+
| Amount | Name | Company |
+---------+------------+----------+
| 1500000 | Pratik | TCS |
| 900000 | Tejas | INFOSYS |
| 1000000 | Kirtesh | Mahindra |
+---------+------------+----------+
3 rows in set (0.00 sec)

4.
mysql> select a.Order_no, a.Amount, b.Company ,b. Credit_Limit from Orders a, Customers b
where a.Cust=b.Cust_no;
+----------+---------+----------+--------------+
| Order_no | Amount | Company | Credit_Limit |
+----------+---------+----------+--------------+
| 101 | 1500000 | TCS | 50000 |
| 102 | 900000 | INFOSYS | 75000 |
| 103 | 1000000 | Mahindra | 60000 |
| 104 | 400000 | Wipro | 55000 |
+----------+---------+----------+--------------+
4 rows in set (0.00 sec)

5.
mysql> select a.Product ,b.Company from Orders a, Customers b where b.Company='TCS' AND
a.Cust= b.Cust_no; +---------+---------+
| Product | Company |
+---------+---------+
| Laptop | TCS |
+---------+---------+
1 row in set (0.00 sec)
6.
mysql> SELECT a.Company, MAX(b.Disc) AS MaxDiscount FROM Orders b JOIN Customers a
ON b.Cust=a.Cust_no GROUP BY a.Company ORDER BY MaxDiscount Desc LIMIT 1;
+---------+-------------+
| Company | MaxDiscount |
+---------+-------------+
| TCS | 150000 |
+---------+-------------+
1 row in set (0.00 sec)

7.
mysql> SELECT a.Name AS Name1, b.Name AS Name2 FROM Sales_Representative a JOIN
Sales_Representative b ON a.Re_office=b.Re_office AND a.Rep_no<>b.Rep_no;
+-----------+-----------+
| Name1 | Name2 |
+-----------+-----------+
| Kirtesh | Pratik |
| Pratik | Kirtesh |
+-----------+-----------+
2 rows in set (0.00 sec)

8.
mysql> SELECT a.Product, SUM(a.Amount) AS Totalamount FROM Orders a GROUP BY
a.Product HAVING SUM(a.Amount)>400000;
+----------+-------------+
| Product | Totalamount |
+----------+-------------+
| Laptop | 1500000 |
| PC | 900000 |
| Monitors | 1000000 |
+----------+-------------+
3 rows in set (0.00 sec)

9.
mysql> SELECT a.Company AS CustomerName, b.Name AS Rep_Name, c.Amount FROM Orders
c JOIN Customers a ON c.Cust=a.Cust_no JOIN Sales_Representative b ON a.Cust_rep=b.Rep_no
WHERE c.Product='Monitors';
+--------------+----------+---------+
| CustomerName | Rep_Name | Amount |
+--------------+----------+---------+
| Mahindra | Kirtesh | 1000000 |
+--------------+----------+---------+
1 row in set (0.00 sec)
10.
mysql> select a.Company,a. Credit_Limit,b. Disc from Customers a,Orders b where
b.Cust=a.Cust_no;
+----------+--------------+--------+
| Company | Credit_Limit | Disc |
+----------+--------------+--------+
| TCS | 50000 | 150000 |
| INFOSYS | 75000 | 90000 |
| Mahindra | 60000 | 100000 |
| Wipro | 55000 | 40000 |
+----------+--------------+--------+
4 rows in set (0.00 sec)

You might also like