基本sql语句

 数据的最基本查询

  

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值