随笔分类 - SQL
万事基础为重,否则为空中楼阁
摘要:1 -- 子查询 2 -- 一句查询语句内,再套一句查询语句 ,叫子查询 3 -- 查询班级类身高最高的人的名字 4 select name from students where high=(select max(high) from students); 5 select id as "序号", name as "姓名",high as "身高...
阅读全文
摘要:-- 分页 -- limit -- limit start count (start 显示骑士值,单页数量) select *from student where gender=1 limit 6,3; -- 分页 -- 以3行为一页,分页 -- 第一页 select *from student limi...
阅读全文
摘要:1 -- 分组 2 -- group by 3 -- 分组只有与聚合函数一起使用才能发挥作用 4 -- 分组只限于字段分明 例如 性别 ,部门, 5 --列出所有性别 6 select gender from student group by gender; 7 --列出所有性别 及数量 8 se...
阅读全文
摘要:1 --聚合函数 2 -- sum() 3 -- 求和 4 select sum(age) from student; 5 6 -- count() 7 -- 求数量 8 -- 数据量 9 select count(*) as '数量' from student; 10 11 -...
阅读全文
摘要:1 -- 排序 2 -- order by 排序 默认为升序 3 -- asc 升序 4 -- desc 降序 5 -- 查询身高 分别用升序和降序 6 select *from student order by high asc; 7 select *from student order by hig...
阅读全文
摘要:转载注明出处:https://www.cnblogs.com/jum-bolg/p/11235427.html
阅读全文
摘要:1 --模糊查询 2 --like 3 --%至少替换一个 4 -- _只替换一个 5 -- 查姓李的人 6 select *from student name like "李%"; 7 -- 查名为杰伦的人 8 select *from student name like "_杰伦"; 9 10 --rlike 11 -- 正则匹配查询 ...
阅读全文
摘要:1 --去重查询 distinct 2 select distinct gander from student; 3 4 --逻辑查询 5 and or not 6 --查询18-28之间的数据 7 select *from student age>18 and age18 and name="lady"; 10 --多条件查询 11 select ...
阅读全文
摘要:前戏 --创建表 create table xxx( id int unsigned not null auto_increment primary key, name varchar(20) not null ); 1.增 --全字段插入 insert into xxx values(0,"王老五
阅读全文
摘要:以下以student表为例 --查看表结构 desc student; --添加字段 alter table student add (字段名)age (数据类型)int unsigned (约束)not null default 0; alter table student add birthda
阅读全文
摘要:1 --登录mysql 2 mysql -uroot -p 3 4 --查看所有库 5 show databases; 6 7 -- 创建数据库 8 -- 不指定编码,默认为拉丁 9 create database `test` charset=utf8; 10 11 -- 查看创建数据库过程 12 show create database `te...
阅读全文