zoukankan      html  css  js  c++  java
  • Mysql数据库基础命令

    删除一个表:

    drop table if exists 表名;

    在表中插入行:

    Insert into 表名 values(, , ,)

    创建表:

    Create table 表名(

    Id int(10)  primary key  auto_increment,               // auto_increment自增的意思

    Name varchar(10),

    Age int unsigned,

    Height decimal(5,2))

    删除行:

    Delete from 表名 where ……

    Tinyint类型 占用一个字节,8个bit,范围是0-255,

    Int类型 占用四个字节

    查询表:

    Select * from 表名  查询表中所有字段

    Select name,age  from 表名   从表中查询name,age列

    Select name as 别名 from 表名  从表中查询name列,并且为name列起一个别名

    Select distinct sex from 表名  从表中查询sex列,只留下不重复的,distinct:不重复

    Select name from 表名 where……  根据条件查询表中name字段

    Select * from 表名 where name like “孙%” 模糊查询,查找表中name为孙X或者孙XX或者孙XXX等等的所有字段

    Select * from 表名 where name like “孙_ _”  查找姓名叫孙XX的所有字段

    Select * from 表名 where name in (“老王”,”老李”,”老孙”)  查找姓名为老王、老李、老孙的字段

    Select * from 表名 where age between 18 and 20  查找年龄在18到20岁之间的所有字段

    Select * from 表名 where age is null  查询没有年龄的所有字段

    排序:

    Select * from 表名 order by age  按照age排序,默认升序(asc)

    Select * from 表名 order by age desc  按照age排序,降序排

    聚合函数:

    Select count(*) from 表名   查询总行数

    Select count(age) from 表名   查询age列的总行数,不包含null

    Select agv(age) from 表名   查询平均年龄

    Select sex,count(*) from  表名 group by sex  having  sex=’男’      查询性别男女分别有多少人,group by是分组,以性别分组,having类似where,后面是条件

    Select * from 表名 limit startNum,count,比如 select* from 表名 limit 0,3  从表中第1行开始,查询三行。

    等值连接:

    Select * from 表1,表2 where 表1.列名 = 表2.列名

    内连接:

    Select * from 表1 inner join 表2 on 表1.字段 = 表2.字段

    Select * from 表1 join 表2 on 连接条件,

                                表2 join 表3 on 连接条件;

                                (后面还可以跟where + 条件 )

    左连接,join换成left join

    右连接,join换成right join

  • 相关阅读:
    在 tornado 中异步无阻塞的执行耗时任务
    django在nginx uwsgi和tornado异步方案在项目中的体验
    使用tornado让你的请求异步非阻塞
    转:Parameter Server 详解
    转:复杂网络分析总结
    从SDCard获取的图片按分辨率处理的方法
    胡振亮:原来这就是非常多站点百度权重做不上去的原因
    c语言函数---I
    [LeetCode] Single Number III
    hdu 5389 Zero Escape (dp)
  • 原文地址:https://www.cnblogs.com/6J2B2/p/12028512.html
Copyright © 2011-2022 走看看