zoukankan      html  css  js  c++  java
  • 第十一周练习题

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


    MariaDB [hellodb]> source /root/hellodb_innodb.sql

    (1) 在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.001 sec)

    (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 |
    +---------+----------+
    8 rows in set (0.001 sec)

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


    MariaDB [hellodb]> select classid,avg(age) as 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.000 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.000 sec)

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

    MariaDB [hellodb]> create user 'magedu'@'192.168.1.%' ;
    Query OK, 0 rows affected (0.011 sec)

    MariaDB [hellodb]> grant all privileges on hellodb.* to 'magedu'@'192.168.1.%' ;
    Query OK, 0 rows affected (0.001 sec)

    因没有设置密码,连接时空密码
    [root@localhost ~]# mysql -umagedu -p
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or g.
    Your MariaDB connection id is 18
    Server version: 10.4.21-MariaDB MariaDB Server

    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]>

  • 相关阅读:
    HDU-3336-Count the string(扩展KMP)
    洛谷-P3805-Manacher模板
    洛谷-p5410-扩展KMP模板
    HDU-2594-Simpsons' Hidden Talents(kmp, 扩展kmp)
    POJ-3080-Blue jeans(KMP, 暴力)
    [办公应用]两个单独的列数据快速变为两列匹配关联数据
    [办公应用]如何将单词中的部分字母加下划线
    [办公应用]word 2007:全屏快捷键,让复制图片保持原样大小(office 全屏快捷键)
    [办公自动化]如何让excel图表标签中显示最新值数据
    [计算机故障处理]无法访问网络共享资源
  • 原文地址:https://www.cnblogs.com/tanll/p/15508525.html
Copyright © 2011-2022 走看看