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。

  • 相关阅读:
    小波变换教程(十五)
    小波变换教程(十四)
    小波变换教程(十三)
    小波变换教程(十二)
    小波变换教程(十一)
    【转】小波变换教程(十)
    利用Python进行数据分析学习记录(一)
    【转】小波变换教程(九)
    小波变换教程(八)
    【转】小波变换教程(七)
  • 原文地址:https://www.cnblogs.com/xlfdqf/p/12307197.html
Copyright © 2011-2022 走看看