摘要:-- 自连接 -- 表自己与自己连接 select a.* from areas as a inner join areas as c on a.pid=c.aid where c.atitle="湖北省"; 表取自: Mysql-几张供于学习的表 - 夜黎i - 博客园 (cnblogs.com)
阅读全文
摘要:-- 子查询 -- 标量子查询:子查询返回的结果是一个数据(一行一列) -- 列子查询:返回的结果是一列(一列多行) -- 行子查询:返回的结果是一行(一行多列) -- 查询出高于平均身高的信息(high) -- 1.查出平均身高 select avg(high) from student; --
阅读全文
摘要:-- 左连接:主表 left join 从表 on 连接条件; -- left join -- 查询每位学生对应的班级信息 select * from student inner join classess on student.cls_id=classess.id; select * from s
阅读全文
摘要:-- 条件查询 -- 比较运算符 -- select …… from 表名 where …… -- > -- 查询身高大于180的信息 select * from student where high>180.00; -- < -- 查询身高小于180的信息 select * from studen
阅读全文
摘要:-- 排序 -- order by 字段 -- asc 从小到大排序,即升序 -- desc 从大到小排序,即降序 -- 查询年龄在18到34岁之间的男性,按照年龄从小到大排序(默认是asc升序)、 select * from student where (age between 18 and 34
阅读全文
摘要:-- 连接查询 -- inner join ... on -- select ... from 表A inner join 表B; select * from student inner join classess; -- 查询 有能够对应班级的学生以及班级信息 select * from stud
阅读全文
摘要:-- 模糊查询(where name like 要查询的数据) -- like -- % 替换任意个 -- _ 替换1个 -- 查询名字中 以“凌”开始的名字 select * from student where name like "凌%"; -- 查询姓名中 有“万”所有的名字 select
阅读全文
摘要:CREATE TABLE `student` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `high` decimal(5,2) DEFAULT NULL, `gender` enum('
阅读全文
摘要:-- 聚合函数 -- 总数 -- count -- 查询男性多少人 select count(*) from student where gender=1; -- 最大值 -- max -- 查询最大的年龄 select max(age) from student; -- 查询女性的最高身高 sel
阅读全文
摘要:-- 分组 -- group by -- 按照性别分组,查询所有的性别 -- 按照字段分组,就可以直接查询什么字段 select gender from student group by gender; -- 计算每种性别中的人数 select gender,count(0) from studen
阅读全文
摘要:-- limit start, count -- start:(页数-1)*每一页的数量 -- 限制查询出来的数据个数 -- 查询前5个数据 select * from student limit 5; -- 每页显示2个,第一个页面 select * from student limit 0,2;
阅读全文
摘要:-- 范围查询 -- in(1,3,8)表示再一个非连续的范围内 -- 查询 年龄为18,20的姓名 select name from student where age=18 or age=20; select name from student where age in(18,20); -- n
阅读全文
摘要:-- 修改 -- update 表名 set 列1=值1, 列2=值2... where 条件; -- 全部修改 update student set cls_id=666; -- 按条件修改 update student set high=188.88 where id=1; 表取自: Mysql
阅读全文
摘要:-- 查看当前数据库中的所有表 show tables; -- 创建表(字段后必须先写数据类型再写约束 数据类型必须有 约束可有可无,根据情况而定) -- int unsigned 无符号整形 -- auto_increment 表示自动增长 -- not null 表示不能为空 -- primar
阅读全文
摘要:-- 查询所有列 -- select * from 表名 select * from student; -- 指定条件查询 select * from student where id=4; -- 查询指定列 -- select 列1,列2,…… from 表名 select name,high f
阅读全文
摘要:-- 删除 -- 物理删除 -- delete from 表名 where 条件 delete from student where id=4; -- 逻辑删除 -- 用一个字段来表示,这条信息是否已经不能再使用了 -- 给student表添加一个 is_delete 字段 bit类型 alter
阅读全文
摘要:-- 连接数据库 -- mysql -uroot -p -- 退出数据库 -- quit/ctrl+d/exit -- 显示数据库版本 select version(); -- 显示时间 select now(); -- 查看当前使用的数据库 select database(); -- 查看所有的数
阅读全文
摘要:-- alter table 表名 add 列名 类型; alter table classess add jixiangwu varchar(30); -- 修改表-修改字段:不重命名版 -- alter table 表名 modify 列名 类型及约束; alter table classess
阅读全文
摘要:-- 增加 -- 全列插入 -- insert [into] 表名 values(...) -- 主键字段 可以用 0 null default 来占位 insert into classess values(0,"python1"); -- 向students表插入 一个学生信息 insert i
阅读全文
摘要:1.在终端中查看mysql数据库 show databases; 2.进入想操作的数据库 use 数据库名; 注:显示 Database changed 即为进入成功。 3.查看数据库中的所有表 show tables; 4.查看表结构 describe(或简写desc)表名;
阅读全文