标签:uid isa can 分组 读取数据 适合 hang let sheng
# 导入hellodb_innodb.sql数据库文件,生成hellodb数据库
[root@centos7 ~]#mysql -uroot -p123456 < hellodb_innodb.sql
# 切换到hellodb数据库
MariaDB [(none)]> use hellodb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
# 查找students表中,年龄大于25岁,且为男性的同学的名字和年龄
MariaDB [hellodb]> 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 |
+--------------+-----+
7 rows in set (0.00 sec)
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 |
+---------+----------+
8 rows in set (0.00 sec)
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 |
+---------+----------+
3 rows in set (0.00 sec)
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)
# 授权magedu用户拥有mysql数据库的所有权限,且设置密码为123456
MariaDB [hellodb]> grant all on mysql.* to magedu@‘192.168.1.%‘ identified by "123456";
Query OK, 0 rows affected (0.00 sec)
标签:uid isa can 分组 读取数据 适合 hang let sheng
原文地址:https://www.cnblogs.com/kfscott/p/13382738.html