Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Salesman Dbms

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

MariaDB [salesmen]> desc salesman;

+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| salesman_id | int(10) | NO | PRI | NULL | |
| name | varchar(50) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| commission | varchar(20) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.026 sec)

MariaDB [salesmen]> desc customer;;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | int(10) | NO | PRI | NULL | |
| cust_name | varchar(20) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| grade | int(10) | YES | | NULL | |
| salesman_id | int(10) | YES | MUL | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.018 sec)

MariaDB [salesmen]> desc orders;


+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| order_no | int(10) | NO | PRI | NULL | |
| purchase_amt | decimal(10,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | int(10) | YES | MUL | NULL | |
| salesman_id | int(10) | YES | MUL | NULL | |
+--------------+---------------+------+-----+---------+-------+
5 rows in set (0.019 sec)

MariaDB [salesmen]> select * from salesman;


+-------------+---------------+-----------+------------+
| salesman_id | name | city | commission |
+-------------+---------------+-----------+------------+
| 1001 | shivram | newyork | 32% |
| 1004 | ramprasadh | new delhi | 12% |
| 1006 | krishna swamy | kolkata | 19% |
| 1009 | rahul | mumbai | 52% |
| 1032 | ajay | mysuru | 26% |
| 1045 | krishna | chennai | 4% |
+-------------+---------------+-----------+------------+
6 rows in set (0.001 sec)

MariaDB [salesmen]> select * from customer;;


+-------------+---------------+-----------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+---------------+-----------+-------+-------------+
| 501 | rohith | bangalore | 10 | 1009 |
| 506 | nithin sharma | kolkata | 6 | 1006 |
| 510 | neethu | mysuru | 19 | 1032 |
| 516 | adithya | mumbai | 46 | 1009 |
| 520 | bheem rao | kolkata | 13 | 1006 |
| 523 | ramdas | chennai | 12 | 1045 |
| 544 | jannifer | newyork | 253 | 1001 |
| 556 | srisha | newyork | 2 | 1001 |
+-------------+---------------+-----------+-------+-------------+
8 rows in set (0.001 sec)

MariaDB [salesmen]> select * from orders;


+----------+--------------+------------+-------------+-------------+
| order_no | purchase_amt | ord_date | customer_id | salesman_id |
+----------+--------------+------------+-------------+-------------+
| 1 | 1000.00 | 2017-05-04 | 556 | 1001 |
| 2 | 3000.00 | 2017-01-20 | 506 | 1006 |
| 3 | 5000.00 | 2017-02-24 | 501 | 1009 |
| 4 | 8000.00 | 2017-04-13 | 520 | 1045 |
| 5 | 18000.00 | 2017-03-09 | 510 | 1032 |
| 7 | 516.00 | 2017-01-20 | 516 | 1009 |
+----------+--------------+------------+-------------+-------------+
6 rows in set (0.001 sec)

MariaDB [salesmen]> select grade,count(customer_id) from customer group by grade


having grade>(select avg(grade) from customer where city='bangalore');
+-------+--------------------+
| grade | count(customer_id) |
+-------+--------------------+
| 12 | 1 |
| 13 | 1 |
| 19 | 1 |
| 46 | 1 |
| 253 | 1 |
+-------+--------------------+
5 rows in set (0.001 sec)

MariaDB [salesmen]> select salesman_id,name from salesman a where 1<(select


count(*) from customer where salesman_id=a.salesman_id);
+-------------+---------------+
| salesman_id | name |
+-------------+---------------+
| 1001 | shivram |
| 1006 | krishna swamy |
| 1009 | rahul |
+-------------+---------------+
3 rows in set (0.001 sec)

MariaDB [salesmen]> select s.salesman_id,name,cust_name, commission from salesman


s, customer c where
s.city=c.city union select salesman_id,name,'no match',commission from salesman
where not city=any(select city from customer)
order by 2 desc;
+-------------+---------------+---------------+------------+
| salesman_id | name | cust_name | commission |
+-------------+---------------+---------------+------------+
| 1001 | shivram | jannifer | 32% |
| 1001 | shivram | srisha | 32% |
| 1004 | ramprasadh | no match | 12% |
| 1009 | rahul | adithya | 52% |
| 1006 | krishna swamy | nithin sharma | 19% |
| 1006 | krishna swamy | bheem rao | 19% |
| 1045 | krishna | ramdas | 4% |
| 1032 | ajay | neethu | 26% |
+-------------+---------------+---------------+------------+
8 rows in set (0.001 sec)

MariaDB [salesmen]> create view vw_high_order_salesman as select b.ord_date,


a.salesman_id ,a.name from salesman a,
orders b where a.salesman_id=b.salesman_id and b.purchase_amt=(select
max(purchase_amt) from
orders c where c.ord_date=b.ord_date);
Query OK, 0 rows affected (0.009 sec)

MariaDB [salesmen]> select * from vw_high_order_salesman;


+------------+-------------+---------------+
| ord_date | salesman_id | name |
+------------+-------------+---------------+
| 2017-05-04 | 1001 | shivram |
| 2017-01-20 | 1006 | krishna swamy |
| 2017-02-24 | 1009 | rahul |
| 2017-04-13 | 1045 | krishna |
| 2017-03-09 | 1032 | ajay |
+------------+-------------+---------------+
5 rows in set (0.003 sec)

MariaDB [salesmen]> select * from salesman;


+-------------+---------------+-----------+------------+
| salesman_id | name | city | commission |
+-------------+---------------+-----------+------------+
| 1001 | shivram | newyork | 32% |
| 1004 | ramprasadh | new delhi | 12% |
| 1006 | krishna swamy | kolkata | 19% |
| 1009 | rahul | mumbai | 52% |
| 1032 | ajay | mysuru | 26% |
| 1045 | krishna | chennai | 4% |
+-------------+---------------+-----------+------------+
6 rows in set (0.001 sec)

MariaDB [salesmen]> delete from salesman where salesman_id=1009;


Query OK, 1 row affected (0.009 sec)

MariaDB [salesmen]> select * from salesman;


+-------------+---------------+-----------+------------+
| salesman_id | name | city | commission |
+-------------+---------------+-----------+------------+
| 1001 | shivram | newyork | 32% |
| 1004 | ramprasadh | new delhi | 12% |
| 1006 | krishna swamy | kolkata | 19% |
| 1032 | ajay | mysuru | 26% |
| 1045 | krishna | chennai | 4% |
+-------------+---------------+-----------+------------+
5 rows in set (0.001 sec)

MariaDB [salesmen]> select * from orders;


+----------+--------------+------------+-------------+-------------+
| order_no | purchase_amt | ord_date | customer_id | salesman_id |
+----------+--------------+------------+-------------+-------------+
| 1 | 1000.00 | 2017-05-04 | 556 | 1001 |
| 2 | 3000.00 | 2017-01-20 | 506 | 1006 |
| 4 | 8000.00 | 2017-04-13 | 520 | 1045 |
| 5 | 18000.00 | 2017-03-09 | 510 | 1032 |
+----------+--------------+------------+-------------+-------------+
4 rows in set (0.002 sec)

MariaDB [salesmen]> select * from orders where salesman_id=1009;


Empty set (0.001 sec)

You might also like