zoukankan      html  css  js  c++  java
  • 4、mysql数据库基础知识

     

    1、创建表:

    create table 表名(

     字段名 类型 约束,

     字段名 类型 约束,

    ……

     

    eg:create table students(

    Id int primary key auto_increment

    name varchar(10),

    age int 

    )

     

    2、删除表:

    方式一:drop table 表名

    方式二:drop table if exists 表名 (如果存在则删除)

     

    3、添加:

    eg:Insert into 表名 values(‘小明’,20,186)

          Insert into 表名 values(‘小明’,20,186),(‘小红’,18,160)

     

    4、删除数据:

    delete from 表名

    eg:delete from students

           delete from students where id=3

     

    5、修改数据:

    update 表名 set 字段=值 where 。。。

    eg:update students set age=18 where id=3

     

    6、查询数据:

    select * from students 查询所有数据

    Select sex from students

    select distinct sex from students 查询去重

     

    7、模糊查询:

    select * from students name like ‘%小%’ 查询名字中包含小的数据

     

    8、排序:

    select * from students order by age asc 按照年龄从小到大排序(默认,升序)

    select * from students order by age desc 按照年龄从大到小排序(降序)

     

    9、分页查询:

    select * from students limit start,count

    eg:select * from students limit 0,3 查询前3条数据

     

    10、聚合函数:

    eg:select count(*) from students 查询学生总数

    eg:select max(age) from students where sex=‘女’ 查询女生最大年龄

    eg:select avg(age) from students where sex=‘女’ 查询女生平均年龄

    eg:select sum(age) from students where addr=‘北京’ 查询北京学生年龄总和

     

    11、分组:

    eg:select sex,count(*) from students group by sex 查询各种性别的总人数

    eg:select class,avg(age),max(age),min(age) from students group by class 查询各个班级学生的平均年龄,最大年龄,最小年龄

    eg:select class,sex,count(*) from students group by class,sex 查询每个班各个性别的人数

     

     

    MySQL简介、命令行工具以及数据管理、MySQL数据查询(条件、分组、聚合函数、排序、分页、连接查询、自关联、子查询)、内置函数、项目练习、数据分表、Python操作MySQL。

  • 相关阅读:
    这是阿里技术专家对 SRE 和稳定性保障的理解
    阿里四年技术 TL 的得失总结:如何做好技术 Team Leader
    深度 | 阿里云蒋江伟:什么是真正的云原生?
    亲历者说 | 完整记录一年多考拉海购的云原生之路
    Seata RPC 模块的重构之路
    对容器镜像的思考和讨论
    20 行代码:Serverless 架构下用 Python 轻松搞定图像分类和预测
    怎么提升写代码的能力
    云原生 DevOps 的 5 步升级路径
    dubbo-go 白话文 | 从零搭建 dubbogo 和 dubbo 的简单用例
  • 原文地址:https://www.cnblogs.com/xlfdqf/p/12307197.html
Copyright © 2011-2022 走看看