mysql数据库命令

删除一个表:函数

drop table if exists 表名;排序

在表中插入行:ci

Insert into 表名 values(, , ,)rem

建立表:it

Create table 表名(table

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

Name varchar(10),im

Age int unsigned,查询

Height decimal(5,2))tab

 

删除行:

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

相关文章
相关标签/搜索