SQL 笔记
1.全查
select * from test; 查询 test表的全部字段
2.查询某个字段的值
select name from test; 查询 test表的name字段
3.查询多个字段的值
select name,type from test; 查询 test表的name,type两个字段的数据
4.条件查询
select * from test where age > 36; 查询 test表中符合过滤条件age> 36的值
select * from test where type='0' and age > 36; 查询 test表中符合过滤条件type='0' 和 age> 36的值
select * from testn where type='0' or age > 36; 查询 test表中符合过滤条件type='0' 或 age> 36的值
5.区间查询
select * from test where age between '10' and '15';查询 test表中符合过滤条件10<=age<=15的值
6.集合查询
select * from test where age in(10,15);
相当于 select * from test where age=‘10’ or age =‘15’;
7.排序
select * from test order by age desc; 以age倒序,显示 test的内容 (order by 默认正序asc)
8.模糊查询
select * from test where name like '%羽%'; 查询name中带有羽的数据
9.求和
select sum(age) from test;
10.多表联合查询
select *from token,test; 查询结果:token表和test表以笛卡尔乘积方式显示
11.插入
insert into test(name,type,age) value('刘备','1','56'); 将value的值对应插入test表的三个字段中
12.修改
update test set type='0' where name='刘备'; 将name为刘备的type改为0
13.删除
delete from test where name='刘备'; 删除test表中name为刘备的内容