I I Iiiiii Sssss

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1. Show .

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
|office |
| sys |
+--------------------+

2. Use.
mysql> use office Database
changed

3. Table showing.
mysql> show tables;
+------------------+
| Tables_in_office |
+------------------+
| workers |
+------------------+

4. Insert.
mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values (1,'Sam',95000,45,'Mal
e','Operations');
Query OK, 1 row affected (0.01 sec)

mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values (2,'Bob',80000,21,'Mal


e','Support');
Query OK, 1 row affected (0.00 sec)

mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values


(3,'Anne',125000,25,'Female','Analysis');
Query OK, 1 row affected (0.00 sec)

mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values (4,'Julia',73000,30,'F


emale','Analysis');
Query OK, 1 row affected (0.00 sec)

mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values (5,'Matt',159000,33,'M


ale','Sales');
Query OK, 1 row affected (0.00 sec)

mysql> insert into workers (e_id,e_name,e_salary,e_age,e_gender,e_dept) values (6,'Jeff',112000,27,'M


ale','Operations');
Query OK, 1 row affected (0.00 sec)

5. Select.
mysql> select * from workers;
+------+--------+----------+-------+----------+------------+
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
+------+--------+----------+-------+----------+------------+
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analysis |
| 4 | Julia | 73000 | 30 | Female | Analysis |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
+------+--------+----------+-------+----------+------------+

6. Sum.
mysql> select sum(e_salary) from workers;
+---------------+
| sum(e_salary) |
+---------------+
| 644000 |
+---------------+

7. Avg.
mysql> select avg(e_salary) from workers;
+---------------+
| avg(e_salary) |
+---------------+
| 107333.3333 |
+---------------+
1 row in set (0.00 sec)

mysql> select avg(e_age) from workers;


+------------+
| avg(e_age) |
+------------+
| 30.1667 |
+------------+

8. Max.
mysql> select max(e_salary) from workers;
+---------------+
| max(e_salary) |
+---------------+
| 159000 |
+---------------+

9. Min.
mysql> select min(e_salary) from workers;
+---------------+
| min(e_salary) |
+---------------+
| 73000 |
+---------------+

10.Count.
mysql> select count(e_id) from workers;
+-------------+
| count(e_id) |
+-------------+
| 6 | +-------------+

11.Where.
mysql> select * from workers where e_age > 21;
+------+--------+----------+-------+----------+------------+
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
+------+--------+----------+-------+----------+------------+
| 1 | Sam | 95000 | 45 | Male | Operations |
| 3 | Anne | 125000 | 25 | Female | Analysis |
| 4 | Julia | 73000 | 30 | Female | Analysis |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
+------+--------+----------+-------+----------+------------+
12.Like.
mysql> select * from workers where e_gender like 'Female';
+------+--------+----------+-------+----------+----------+
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
+------+--------+----------+-------+----------+----------+
| 3 | Anne | 125000 | 25 | Female | Analysis |
| 4 | Julia | 73000 | 30 | Female | Analysis |
+------+--------+----------+-------+----------+----------+
2 rows in set (0.00 sec)

mysql> select * from workers where e_gender like 'Male';


+------+--------+----------+-------+----------+------------+
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
+------+--------+----------+-------+----------+------------+
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
+------+--------+----------+-------+----------+------------+
4 rows in set (0.00 sec)

You might also like