- 模糊查询
%张% 含有张
select 列名 from 表名 where 列名 like ‘%张%’;
张% 以张开头 可以是个n个字符
select 列名 from 表名 where 列名 like ‘张%’ ;
张_ 张开头 两个字符 张三 张四
select 列名 from 表名 where 列名 like‘张_’; - And 和
Select * from 表名 where 列名=‘1’ and sex=‘1’; - Or 或
select * from 表名 where 列名 like '张%‘or 列名 like’李%’; - 升序:selectfrom 表名 order by id asc;
降序:selectfrom 表名 order by id desc; - 限制条数
select * from 表名 limit 0,3; - 判断某字段不为空
select * from 表名 where 列名 is not null; - 清空数据表 truncate table 表名;
- 删除表 drop table 表名;
- 删库 drop database 库名;
sql:数据库与程序通讯的语言。
insert intostudent2
(sname
,sex
,card
,phone
,birthday
,addtime
,intro
) values (‘222)’,null,null,null,null,null,null);
聚合函数
count(*) 统计数目
sum 求和
min 最小值
max 最大值
avg 平均值
select count(*) as ‘数量’,sex as ‘性别’ from
student2 where 1
group by sex //根据 sex 分组
select * from student2
where age between 15 and 28
条件
where 分组前的条件
having 对分组后的查询结果进行条件限制
SELECT COUNT(),sex FROM
student2 WHERE 1 AND age>14
GROUP BY sex
HAVING COUNT()>5
统计条数:
Select count(*) from 表名;
(列名)+最大值
Select max(列名)from 表名;
+平均值
Select avg(列名)from 表名;
+求和
Select sum(列名)from 表名;
Update 表名 set 列名;//默认全部
Update 表名 set 列名=1;//默认=1的
Select count(*)from student where sex=1;
Select count(*)as ‘数量’,sex as ‘性别’from
student where 1
Group by sex;//根据列名分组
Update student
set age=18 where sid<9//存年龄
select avg(age),sex from student//求平均年龄
where 1 group by sex //
select count(*) from(select ssex from student group by ssex//统计种)as a student where ssex
select sname,drgee from
student as s join score as c
on s.sno=c.sno