Linux第11周

1、 导入hellodb.sql生成数据库

[root@centos8-2 ~]# yum -y install mysql-server
[root@centos8-2 ~]# systemctl enable --now mysqld
[root@centos8-2 ~]# rz -E
rz waiting to receive.
[root@centos8-2 ~]# mysql
mysql> source hellodb_innodb.sql

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| hellodb |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄

mysql> use hellodb;
Database changed
mysql> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.00 sec)
mysql> select *from students;
mysql> select name,age from students where age>25 and gender='M';
+--------------+-----+
| name | age |
+--------------+-----+
| Xie Yanke | 53 |
| Ding Dian | 32 |
| Yu Yutong | 26 |
| Shi Qing | 46 |
| Tian Boguang | 33 |
| Xu Xian | 27 |
| Sun Dasheng | 100 |
+--------------+-----+

(2) 以ClassID为分组依据linux,显示每组的平均年龄

mysql> select classid,avg(age) from students group by classid order by classid ASC;
+---------+----------+
| classid | avg(age) |
+---------+----------+
| NULL | 63.5000 |
| 1 | 20.5000 |
| 2 | 36.0000 |
| 3 | 20.2500 |
| 4 | 24.7500 |
| 5 | 46.0000 |
| 6 | 20.7500 |
| 7 | 19.6667 |
+---------+----------+