Aritmetic Operators:
1) Addition(+):
mysql> select Orderid, Ordername, OrderPrice , OrderPrice +10 as "OrderPrice + GST" from
Orders;
+---------+----------------------+------------+------------------+
| Orderid | Ordername | OrderPrice | OrderPrice + GST |
+---------+----------------------+------------+------------------+
| 146 | Southy Special | 200 | 210 |
| 167 | Triple Schezwan Rice | 250 | 260 |
| 211 | PavBhaji | 220 | 230 |
| 231 | Gujarathi Special | 850 | 860 |
| 456 | Lava Cake | 280 | 290 |
| 516 | Paneer Kadai | 350 | 360 |
+---------+----------------------+------------+------------------+
6 rows in set (0.00 sec)
2) Subtraction(-):
mysql> select Orderid, Ordername, OrderPrice , OrderPrice -10 as "OrderPrice -GST" from
Orders;
+---------+----------------------+------------+-----------------+
| Orderid | Ordername | OrderPrice | OrderPrice -GST |
+---------+----------------------+------------+-----------------+
| 146 | Southy Special | 200 | 190 |
| 167 | Triple Schezwan Rice | 250 | 240 |
| 211 | PavBhaji | 220 | 210 |
| 231 | Gujarathi Special | 850 | 840 |
| 456 | Lava Cake | 280 | 270 |
| 516 | Paneer Kadai | 350 | 340 |
+---------+----------------------+------------+-----------------+
6 rows in set (0.00 sec)
3) Multiplication(*):
mysql> select Orderid, Ordername, OrderPrice , OrderPrice * 10 as "OrderPrice * GST"
from Orders;
+---------+----------------------+------------+------------------+
| Orderid | Ordername | OrderPrice | OrderPrice * GST |
+---------+----------------------+------------+------------------+
| 146 | Southy Special | 200 | 2000 |
| 167 | Triple Schezwan Rice | 250 | 2500 |
| 211 | PavBhaji | 220 | 2200 |
| 231 | Gujarathi Special | 850 | 8500 |
| 456 | Lava Cake | 280 | 2800 |
| 516 | Paneer Kadai | 350 | 3500 |
+---------+----------------------+------------+------------------+
6 rows in set (0.00 sec)
4) Division (/):
mysql> select Orderid, Ordername, OrderPrice , OrderPrice / 10 as "OrderPrice / GST"
from Orders;
+---------+----------------------+------------+------------------+
| Orderid | Ordername | OrderPrice | OrderPrice / GST |
+---------+----------------------+------------+------------------+
| 146 | Southy Special | 200 | 20.0000 |
| 167 | Triple Schezwan Rice | 250 | 25.0000 |
| 211 | PavBhaji | 220 | 22.0000 |
| 231 | Gujarathi Special | 850 | 85.0000 |
| 456 | Lava Cake | 280 | 28.0000 |
| 516 | Paneer Kadai | 350 | 35.0000 |
+---------+----------------------+------------+------------------+
6 rows in set (0.00 sec)
5) Modulus(%):
mysql> select Orderid, Ordername, OrderPrice , OrderPrice % 10 as "OrderPrice % GST"
from Orders;
+---------+----------------------+------------+------------------+
| Orderid | Ordername | OrderPrice | OrderPrice % GST |
+---------+----------------------+------------+------------------+
| 146 | Southy Special | 200 | 0|
| 167 | Triple Schezwan Rice | 250 | 0|
| 211 | PavBhaji | 220 | 0|
| 231 | Gujarathi Special | 850 | 0|
| 456 | Lava Cake | 280 | 0|
| 516 | Paneer Kadai | 350 | 0|
+---------+----------------------+------------+------------------+
6 rows in set (0.00 sec)
Relational Operators:
1 . Equal to (=)
mysql> select *from UserDetails where Address="Nashik";
+-----+----------+-----------+---------+--------------------+
| id | UserName | Contact | Address | Email |
+-----+----------+-----------+---------+--------------------+
| 101 | Shraddha | 908902332 | Nashik |
[email protected] |
| 102 | Amit | 965676792 | Nashik |
[email protected] |
| 103 | Amay | 98540423 | Nashik |
[email protected] |
| 106 | Arush | 945665439 | Nashik |
[email protected] |
+-----+----------+-----------+---------+--------------------+
4 rows in set (0.00 sec)
2: Not equal to (<>)
mysql> select *from UserDetails where Address<>"Nashik";
+-----+----------+-----------+-------------+--------------------+
| id | UserName | Contact | Address | Email |
+-----+----------+-----------+-------------+--------------------+
| 104 | Sneha | 923518493 | Jail Road |
[email protected] |
| 105 | Aarohi | 984634329 | Nashik road |
[email protected] |
+-----+----------+-----------+-------------+--------------------+
2 rows in set (0.00 sec)
Greater than or equal to (>=)
mysql> select Orderid, Ordername, OrderPrice from Orders where OrderPrice >= 300 ;
+---------+-------------------+------------+
| Orderid | Ordername | OrderPrice |
+---------+-------------------+------------+
| 231 | Gujarathi Special | 850 |
| 516 | Paneer Kadai | 350 |
+---------+-------------------+------------+
2 rows in set (0.00 sec)
Boolean Operators:
AND
mysql> select foodname , price from fooditems where quantity =1 and price <=300;
+------------------------+-------+
| foodname | price |
+------------------------+-------+
| Paneer Butter Masala | 290 |
| Veg Biryani with Salad | 190 |
+------------------------+-------+
2 rows in set (0.00 sec)
OR Operator:
mysql> select foodname , price from fooditems where quantity =2 or price <=300;
+------------------------+-------+
| foodname | price |
+------------------------+-------+
| Pav Bhaji | 250 |
| Paneer Butter Masala | 290 |
| Veg Biryani with Salad | 190 |
| Cheese Grill Sandwitch | 150 |
+------------------------+-------+
4 rows in set (0.00 sec)
BETWEEN Operator:
mysql> select id, foodname , price from fooditems where id between 120 and 160;
+------+----------------------+-------+
| id | foodname | price |
+------+----------------------+-------+
| 151 | Pav Bhaji | 250 |
| 151 | Paneer Butter Masala | 290 |
| 123 | Chinese Plate | 350 |
+------+----------------------+-------+
3 rows in set (0.00 sec)
min
mysql> select Orderid, Ordername , min(OrderPrice) as Price from Orders group by
Orderid;
+---------+----------------------+-------+
| Orderid | Ordername | Price |
+---------+----------------------+-------+
| 146 | Southy Special | 200 |
| 167 | Triple Schezwan Rice | 250 |
| 211 | PavBhaji | 220 |
| 231 | Gujarathi Special | 850 |
| 456 | Lava Cake | 280 |
| 516 | Paneer Kadai | 350 |
+---------+----------------------+-------+
6 rows in set (0.00 sec)
count
mysql> select count(*) as TotalOrders from Orders ;
+-------------+
| TotalOrders |
+-------------+
| 6|
+-------------+
1 row in set (0.00 sec)
Avg:
mysql> select Avg(OrderPrice) as AvgPrice, Ordername from Orders group by Orderid ;
+----------+----------------------+
| AvgPrice | Ordername |
+----------+----------------------+
| 200.0000 | Southy Special |
| 250.0000 | Triple Schezwan Rice |
| 220.0000 | PavBhaji |
| 850.0000 | Gujarathi Special |
| 280.0000 | Lava Cake |
| 350.0000 | Paneer Kadai |
+----------+----------------------+
6 rows in set (0.00 sec)
Pattern Matching:
mysql> select distinct UserName, Address from UserDetails where UserName like
'%ha';
+----------+-----------+
| UserName | Address |
+----------+-----------+
| Shraddha | Nashik |
| Sneha | Jail Road |
+----------+-----------+
2 rows in set (0.00 sec)
set operators
mysql> select Address from UserDetails UNION select Address From Restuarant ;
+-------------+
| Address |
+-------------+
| Nashik |
| Jail Road |
| Nashik road |
| nagur |
| nagpur |
| kolhapur |
+-------------+
6 rows in set (0.00 sec)
mysql> select Address from UserDetails Except select Address From Restuarant ;
+-------------+
| Address |
+-------------+
| Jail Road |
| Nashik road |
+-------------+
2 rows in set (0.00 sec)
mysql> select Address from UserDetails Intersect select Address From Restuarant ;
+---------+
| Address |
+---------+
| nashik |
+---------+
1 row in set (0.00 sec)
mysql> select Orderid, Ordername, OrderPrice from Orders order by Orderid;
+---------+----------------------+------------+
| Orderid | Ordername | OrderPrice |
+---------+----------------------+------------+
| 146 | Southy Special | 200 |
| 167 | Triple Schezwan Rice | 250 |
| 211 | PavBhaji | 220 |
| 231 | Gujarathi Special | 850 |
| 456 | Lava Cake | 280 |
| 516 | Paneer Kadai | 350 |
+---------+----------------------+------------+
6 rows in set (0.01 sec)
mysql> select count(Adminid), AdminName from Admin GROUP BY AdminName;
+----------------+-----------+
| count(Adminid) | AdminName |
+----------------+-----------+
| 1 | Amit |
| 1 | Sakshi |
| 1 | Aditya |
| 1 | Yash |
+----------------+-----------+
4 rows in set (0.04 sec)