马哥——第十一周

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

[root@centos7 ~]#mysql < hellodb_innodb.sql
MariaDB [hellodb]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db3                |
| hellodb            |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)

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

MariaDB [hellodb]> select name,age,gender  from students where age>25 and gender='M';
+--------------+-----+--------+
| name         | age | gender |
+--------------+-----+--------+
| Xie Yanke    |  53 | M      |
| Ding Dian    |  32 | M      |
| Yu Yutong    |  26 | M      |
| Shi Qing     |  46 | M      |
| Tian Boguang |  33 | M      |
| Xu Xian      |  27 | M      |
| Sun Dasheng  | 100 | M      |
+--------------+-----+--------+
7 rows in set (0.00 sec)

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

MariaDB [hellodb]> select classid,avg(age)平均年龄  from students  group by classid ;
+---------+--------------+
| classid | 平均年龄     |
+---------+--------------+
|    NULL |      63.5000 |
|       1 |      20.5000 |
|       2 |      36.0000 |
|       3 |      20.2500 |
|       4 |      24.7500 |
|       5 |      46.0000 |
|       6 |      20.7500 |
|       7 |      19.6667 |
+---------+--------------+
8 rows in set (0.00 sec)

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

MariaDB [hellodb]> select classid,avg(age)平均年龄  from students  group by classid having 平均年龄>30;
+---------+--------------+
| classid | 平均年龄     |
+---------+--------------+
|    NULL |      63.5000 |
|       2 |      36.0000 |
|       5 |      46.0000 |
+---------+--------------+
3 rows in set (0.00 sec)

(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 |
+-------+-------------+-----+--------+---------+-----------+
3 rows in set (0.00 sec)

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

MariaDB [hellodb]> create user magedu@"192.168.1.%" identified by "123456";Query OK, 0 rows affected (0.00 sec)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值