Java教程

第十一周

本文主要是介绍第十一周,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

第十一周
1、 导入hellodb.sql生成数据库
(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄

MariaDB [hellodb]> select Name,Gender,Age from students where Age>25 and Gender='M';
+--------------+--------+-----+
| Name | Gender | Age |
+--------------+--------+-----+
| Xie Yanke | M | 53 |
| Ding Dian | M | 32 |
| Yu Yutong | M | 26 |
| Shi Qing | M | 46 |
| Tian Boguang | M | 33 |
| Xu Xian | M | 27 |
| Sun Dasheng | M | 100 |
+--------------+--------+-----+


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

MariaDB [hellodb]> select ClassID,avg(age) from students group by ClassID;
+---------+----------+
| 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 |
+---------+----------+


(3) 显示第2题中平均年龄大于30的分组及平均年龄

MariaDB [hellodb]> select ClassID,avg(age) from students group by ClassID having avg(age)>30;
+---------+----------+
| ClassID | avg(age) |
+---------+----------+
| NULL | 63.5000 |
| 2 | 36.0000 |
| 5 | 46.0000 |
+---------+----------+


(4) 显示以L开头的名字的同学的信息

MariaDB [hellodb]> select * from students where name like 'L%';
+-------+-------------+-----+--------+---------+-----------+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+-------+-------------+-----+--------+---------+-----------+
| 8 | Lin Daiyu | 17 | F | 7 | NULL |
| 14 | Lu Wushuang | 17 | F | 3 | NULL |
| 17 | Lin Chong | 25 | M | 4 | NULL |
+-------+-------------+-----+--------+---------+-----------+


2、数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

MariaDB [hellodb]> grant all on *.* to magedu@'192.168.1.%';

这篇关于第十一周的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!