查询语句
selete 语句
select 字段1,字段2,...字段n from 表名 where [条件]
查询所有字段所有记录
select * from 表名;
‘*’ 统配标识符 匹配所有记录
查询(指定)部分字段的记录
select 字段1,字段2,...字段n from 表名;
查询符合条件的记录
==条件语句:where ==
= 等于
!=/<> 不等于
< 小于
> 大于
<= 小于等于
>= 大于等于
between.... and .... 在...和...之间 也可以查询名字为xxx的(字符串匹配)
in(值1,值2......) 是否是其中的一个值
not in 与上面的正好不一样
like 相似 模糊匹配
1.% 百分号通配符 匹配任意长度的
select * from student where name like "H%";
2._ 下划线通配符 匹配单个字符的
select * from student where name like "H____";
查询空值
is null;
is not null;
select * from student where age is null;
select * from student where age is not null;
多个条件查询
and 相当于 &&
or 相当于 ||
去重 distinct
select distinct score from student ;
我看来有点鸡肋
排列查询(默认是升序排列asc)
select * from student order by score asc;
select * from student order by score desc;(降序排列)
指定查询数量
limit
(常见于网站的的查询页,反页)
select * from student limit 4;
查出按照 插入信息的顺序的前四个
select * from student limit 4,8;
查出按照插入信息的顺序的4-8个;
查询某个条件的记录数量:
count
select count(*) from student;
select count(*) as count(这里是命个名) from student;
select count(*) as count from student where[条件];
一些计算的函数
sum()
select sum(score) total from student;
select sum(score) as total from student;
avg()
select avg(score) avgs from student;
删除记录
delete from 表 where id=1;
删除id为1的记录
修改记录(更新数据)
updata
updata student set sex = "" where [条件]
修改多个字段
updata student
set
sex="女";
age = 25;
while [条件];
不写条件就全改了,很危险
一定要写条件,条件不对也很危险