mariadb示例1

Table of Contents

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

    mysql < hellodb.sql
  2. 在 students 表中,查询年龄大于 25 岁,且为男性的同学的名字和年龄

    SELECT Name,Age FROM students WHERE Age>25 AND Gender='M';
  3. 在 students 表中,以 ClassID 为分组依据,显示每组的平均年龄

    SELECT Classid,AVG(Age) FROM students GROUP BY Classid;
  4. 在 students 表中,显示平均年龄大于 30 的分组及平均年龄

    SELECT Classid,AVG(Age) AS age FROM students GROUP BY Classid HAVING age>30;
  5. 在 students 表中,显示以 L 开头的名字的同学的信息

    SELECT * FROM students WHERE name LIKE 'L%';
  6. 数据库授权 chao 用户,允许 192.168.11.0/24 网段可以连接 mysql

    CREATE USER 'chao'@'192.168.11.%' IDENTIFIED BY '密码';

猜你喜欢

转载自www.cnblogs.com/chaoyiyang/p/12148350.html