Table Descriptions:
Customers :{ salesmanID : “The One who Onboarder this customer”, };
Orders {parchaseAmt: “Amount of transaction”,orderDT:”Order Date”,customerId ; “Konsa
CUstomer”, “salesmanId ”:”the One who sold the item” }
Salesman {commision:”%age of amount earned by salesman on any sale”}
Q1: Name The Salesman who has onboarded the max no Of Customers.
select count(*), salesmanID from customers group by salesmanID order by(count(*)) DESC
limit 1;
+----------+------------+
| count(*) | salesmanID |
+----------+------------+
| 17 | 7 |
+----------+------------+
1 row in set (0.00 sec)
Q2: Name the salesman with the 3 highest commision %age;
select* from salesman order by commission DESC limit 3;
+------------+------------+---------+------------+
| salesmanID | name | city | commission |
+------------+------------+---------+------------+
| 6 | Salesman6 | Noida | 10.00 |
| 10 | Salesman10 | Delhi | 10.00 |
| 8 | Salesman8 | Gurgaon | 8.00 |
+------------+------------+---------+------------+
Q3: Name the salesman from Noida?
select * from salesman where city= 'Noida';
+------------+-----------+-------+------------+
| salesmanID | name | city | commission |
+------------+-----------+-------+------------+
| 3 | Salesman3 | Noida | 4.00 |
| 6 | Salesman6 | Noida | 10.00 |
| 9 | Salesman9 | Noida | 0.00 |
+------------+-----------+-------+------------+
Q4: Name all the distinct cities in which the Company work in;
select distinct (city) from salesman;
+---------+
| city |
+---------+
| Delhi |
| Gurgaon |
| Noida |
+---------+
Q5: Which city has the highest number of employees?
select count(*), salesmanID, city from salesman group by city order by (count(*)) desc limit 1;
+----------+------------+-------+
| count(*) | salesmanID | city |
+----------+------------+-------+
| 4 | 1 | Delhi |
+----------+------------+-------+
Q6: What %age of revenue is lost in commisions according to cities? (Do not count
according to GMV)
mysql> select sum(commission) as DELHICOMMISSION from salesman where city= 'Delhi';
+-----------------+
| DELHICOMMISSION |
+-----------------+
| 22.00 |
+-----------------+
1 row in set (0.00 sec)
mysql> select sum(commission) as GURGAONCOMMISSION from salesman where city=
'Gurgaon';
+-------------------+
| GURGAONCOMMISSION |
+-------------------+
| 17.00 |
+-------------------+
1 row in set (0.00 sec)
mysql> select sum(commission) as NoidaCOMMISSION from salesman where city= 'Noida';
+-----------------+
| NoidaCOMMISSION |
+-----------------+
| 14.00 |
+-----------------+
Q7: Which city losses the max number of revune in terms of %age alloted to its employees?
(Do not count according to GMV)
Q8: Which city has the 2nd Hisgest Customers?
select count(customername), city from customers group by city;
+---------------------+---------+
| count(customername) | city |
+---------------------+---------+
| 34 | Delhi |
| 33 | Gurgaon |
| 33 | Noida |
+---------------------+---------+
Q9: Name the 3 Highest order in DELHI under Salesman 6?
select orders.purchaseamt, customers.customername, customers.city from orders inner join
customers on orders.salesmanID= customers. salesmanID where city= "delhi" order by
purchaseamt desc limit 3 ;
+-------------+--------------+-------+
| purchaseamt | customername | city |
+-------------+--------------+-------+
| 9996.00 | Customer7 | Delhi |
| 9996.00 | Customer19 | Delhi |
| 9996.00 | Customer4 | Delhi |
+-------------+--------------+-------+
3 rows in set (0.13 sec)
mysql> select orders.purchaseamt, customers.customername, customers.city from orders
inner join customers on orders.salesmanID= customers. salesmanID where city= "delhi" and
salesmanID= '6' order by purchaseamt desc limit 3 ;
ERROR 1052 (23000): Column 'salesmanID' in where clause is ambiguous
mysql> select orders.purchaseamt, customers.customername, customers.city from orders
inner join customers on orders.salesmanID= customers. salesmanID where city= "delhi"
order by purchaseamt desc limit 3 group by salesmanID;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'group by
salesmanID' at line 1
mysql> select orders.purchaseamt, orders.orderID, customers.customername,
customers.city from orders inner join customers on orders.salesmanID= customers.
salesmanID where city= "delhi" order by purchaseamt desc limit 3 group by salesmanID;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'group by
salesmanID' at line 1
mysql> select orders.purchaseamt, orders.orderID, customers.customername,
customers.city from orders inner join customers on orders.salesmanID= customers.
salesmanID where city= "delhi" order by purchaseamt desc limit 3 ;
ERROR 1054 (42S22): Unknown column 'orders.orderID' in 'field list'
mysql> select orders.purchaseamt, orders.salesmanID, customers.customername,
customers.city from orders inner join customers on orders.salesmanID= customers.
salesmanID where city= "delhi" order by purchaseamt desc limit 3 ;
+-------------+------------+--------------+-------+
| purchaseamt | salesmanID | customername | city |
+-------------+------------+--------------+-------+
| 9996.00 | 7 | Customer4 | Delhi |
| 9996.00 | 7 | Customer19 | Delhi |
| 9996.00 | 7 | Customer7 | Delhi |
+-------------+------------+--------------+-------+
Q10: Which is 10 Least transacting user? (In terms of number of times transacted)
select count(*), customerID from orders group by customerid order by count(*) limit 10;
+----------+------------+
| count(*) | customerID |
+----------+------------+
| 1 | 60 |
| 1 | 48 |
| 1 | 57 |
| 2 | 31 |
| 3 | 89 |
| 3 | 99 |
| 3 | 81 |
| 3 | 75 |
| 3 | 20 |
| 3 | 45 |
+----------+------------+
10 rows in set (0.00 sec)
Q11: Which is the 10 Least transacting User? (In terms of GMV)
select purchaseamt, customerID from orders group by customerID order by purchaseamt
limit 10;
+-------------+------------+
| purchaseamt | customerID |
+-------------+------------+
| 79.00 | 82 |
| 249.00 | 88 |
| 263.00 | 72 |
| 321.00 | 19 |
| 334.00 | 27 |
| 390.00 | 83 |
| 439.00 | 25 |
| 524.00 | 40 |
| 692.00 | 20 |
| 866.00 | 10 |
+-------------+------------+
10 rows in set (0.00 sec)
Q12: Which state provides the max number of transactions?
select purchaseamt, customers.city from orders inner join customers on orders.customerID=
customers.customerID group by city order by purchaseamt limit 1;
+-------------+---------+
| purchaseamt | city |
+-------------+---------+
| 2841.00 | Gurgaon |
+-------------+---------+
1 row in set (0.01 sec)
mysql> select count(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by purchaseamt limit 1;
+--------------------+---------+
| count(purchaseamt) | city |
+--------------------+---------+
| 216 | Gurgaon |
+--------------------+---------
Or------------------------------------------------------------
select count(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by count(purchaseamt) desc;
+--------------------+---------+
| count(purchaseamt) | city |
+--------------------+---------+
| 222 | Delhi |
| 216 | Gurgaon |
| 182 | Noida |
+--------------------+---------+
3 rows in set (0.01 sec)
mysql> select count(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by count(purchaseamt) desc
limit 1;
+--------------------+-------+
| count(purchaseamt) | city |
+--------------------+-------+
| 222 | Delhi |
+--------------------+-------+
Q13: which city provides the Higest GMV?
See above question 1st part
select purchaseamt, customers.city from orders inner join customers on orders.customerID=
customers.customerID group by city order by purchaseamt desc;
+-------------+---------+
| purchaseamt | city |
+-------------+---------+
| 9133.00 | Delhi |
| 3523.00 | Noida |
| 2841.00 | Gurgaon |
+-------------+---------+
3 rows in set (0.01 sec)
Q14: Which city provides the The max avg Transaction AMount?
select orders.purchaseamt, customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city;
+-------------+---------+
| purchaseamt | city |
+-------------+---------+
| 9133.00 | Delhi |
| 2841.00 | Gurgaon |
| 3523.00 | Noida |
+-------------+---------+
3 rows in set (0.01 sec)
mysql> select orders.avg(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city;
ERROR 1630 (42000): FUNCTION orders.avg does not exist. Check the 'Function Name
Parsing and Resolution' section in the Reference Manual
mysql> select AVG(purchaseamt) from orders (select orders.purchaseamt, customers.city
from orders inner join customers on orders.customerID= customers.customerID) group by
city ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '(select
orders.purchaseamt, customers.city from orders inner join customers on o' at line 1
mysql> select AVG(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city;
+------------------+---------+
| AVG(purchaseamt) | city |
+------------------+---------+
| 4850.270270 | Delhi |
| 4900.157407 | Gurgaon |
| 4948.813187 | Noida |
+------------------+---------+
3 rows in set (0.05 sec)
mysql> select AVG(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by DESC
AVG(purchaseamt);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'DESC
AVG(purchaseamt)' at line 1
mysql> select AVG(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by DESC purchaseamt;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'DESC
purchaseamt' at line 1
mysql> select AVG(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by AVG(purchaseamt) desc;
+------------------+---------+
| AVG(purchaseamt) | city |
+------------------+---------+
| 4948.813187 | Noida |
| 4900.157407 | Gurgaon |
| 4850.270270 | Delhi |
+------------------+---------+
3 rows in set (0.01 sec)
mysql> select AVG(purchaseamt), customers.city from orders inner join customers on
orders.customerID= customers.customerID group by city order by AVG(purchaseamt) desc
limit 1;
+------------------+-------+
| AVG(purchaseamt) | city |
+------------------+-------+
| 4948.813187 | Noida |
+------------------+-------+
Q15: Name the user (?) and the salesman, with higest transaction amount ever, and the
onboarder of the customer (ISnt it the salesman itself)?
select MAX(purchaseamt), customers.customername, salesman.name from orders inner join
customers on orders.customerid= customers.customerid inner join salesman on
customers.salesmanID= salesman.salesmanID;
+------------------+--------------+-----------+
| MAX(purchaseamt) | customername | name |
+------------------+--------------+-----------+
| 9996.00 | Customer65 | Salesman2 |
+------------------+--------------+-----------+
Q16: Name the MOst Important Customer? (amount)
Whose purchase amount in total is max:
select orders.purchaseamt, orders.customerID, customers.customername from orders inner
join customers on orders.customerID= customers.customerID group by customername order
by purchaseamt desc limit 1;
+-------------+------------+--------------+
| purchaseamt | customerID | customername |
+-------------+------------+--------------+
| 9996.00 | 90 | Customer90 |
+-------------+------------+--------------+
Q17: Name the salesman with max number of transactions
select count(purchaseamt), salesman.salesmanID, salesman.name from orders inner join
salesman on orders.salesmanID= salesman.salesmanid group by salesmanID order by
count(purchaseamt) desc limit 1;
+--------------------+------------+-----------+
| count(purchaseamt) | salesmanID | name |
+--------------------+------------+-----------+
| 72 | 6 | Salesman6 |
+--------------------+------------+-----------+
Q18: Name the salesman that gave the highest GMV?
Max purchase amt:
select purchaseamt, salesman.salesmanID, salesman.name from orders inner join
salesman on orders.salesmanID= salesman.salesmanid group by salesmanID order by
purchaseamt desc limit 1;
+-------------+------------+-----------+
| purchaseamt | salesmanID | name |
+-------------+------------+-----------+
| 9996.00 | 7 | Salesman7 |
+-------------+------------+-----------+
Q19: The Salesman, whos onboards have led to highest GMV?
Q20: Name the salesman, who took the 3rd lowest Commision in terms of GMV?
Q21: Name the salesman, whose commision to GMV provided is the 2nd Lowest?
Q22: Name the greadiest Salesman?
On basis of what , on basis if he brought maximum customers or maximum transactions?/
Q23: Calculate the total amount the company ows to salesman as commision.
Q24: Which city rakes the highest commison?
Q25: MVP (revenue) City?