数据的最基本查询
select * from A
//查询表名为A的全部数据
select * from A where name=’a’
//查询表名为A且字段name为a的全部数据
select * from A where name='a' and nick='b'
//查询表名为A且字段name为a,字段nick为b的全部数据
select * from A where name in ( ‘a1’ , ‘a2’)
//查询表名为A且字段name为a1或者a2的全部数据
select * from A where name like ‘%张%’
//查询表名为A且字段name为带张字的全部数据,模糊查询(张前后可多个字符)
select * from A where name like ‘_张_’
//查询表名为A且字段name为带张字的全部数据,模糊查询(张前后可一个字符)
select * from A where name is null
//查询表名为A且name为空值的全部数据
select nick from A;
//查询表名为A的全部nick数据
数据高级一点的查询
select sum(age) as a from A;
//表名为A中的字段age的和(count 统计,avg 平均,max最大值等)
select count(name) from A group by type
//查询表名为A的字段name的总数按字段type分组
select count(name) from A group by type having type=’a’
//查询表名为A的字段name的总数按字段type分组,得出type为a的分组数据
select * from A order by time asc
//查询表名为A中的全部数据,按字段time升序,默认升序 asc升序,desc降序
select R.a, S.b from R,S where (R.no=S.no) and b=’b’;
//多表查询
select name from A where nick=(select nick from B where Id=1)
//嵌套查询,查询表名为B中的字段Id等于1的字段nick在表A中的字段name的数据
select * from A where name='a' limit 10;
//查询表名为A中的字段age值在1-20区间的10条数据
select * from A where age between 1 and 20;
//查询表名为A中的字段age值在1-20区间的全部数据
select * from A where age > 1;
//查询表名为A中的字段age值大于1的全部数据,包括大于、等于、小于、大于等于、小于等于
数据的增删改
insert into A(a1 , a2 , a3) values (‘a1’ , ’a2’ ,’ a3’);
//添加数据
delete * from A where Id=1
//删除表名为A中的字段id等于1的数据
update A set nick=’a’ where name=’b’
//更新表名为A的字段name为b的nick为a