sql语句入门
查询语句
- select 字段,字段 from 表名:
例如:select ‘name’ from Dataset
表名或字段名加上‘’ 会加快sql语句的执行速度 - select * 表示搜寻所有数段
例如:select * from ‘ sss’ where ‘id=2’
不等于!= 和 <> 等价- 条件判断 > , < ,<= ,>=
- in 的使用
例如select * from ’ ss’ where ‘id’ in (1,2,4) 查询ss表中的值在()里面的数据- not in
- between的使用
例如select * from ‘ss’ where ‘id’ between 2 and 4
select * from ‘ss’ order by ‘time’ desc
按照时间的降序排序- desc降序
- asc升序
- order by 语句需要在where的后面
- limit 限制条数
例如 select * from ‘aa’ where ‘ID’ in(1,3,4)order by desc limit 0,2
只查找前两行
count
- select count(*) from ’ ss’
查询表中总的数据条数- select count(*) as pp from ‘ss’
通过as语句取别名pp
- select count(*) as pp from ‘ss’
max(min、average)
- select max9(id) from ‘ss’’
查询ss表中id最大的值
添加
insert into 表名(字段名,字段名,—) value (值,值,----)
修改
update 表名 set 字段=值 ······ where 条件
例如 update ‘ss’’ set ‘name’=‘user’,‘pwd’=‘2’
删除
delet from 表名 where 条件
例如 delete from ‘ss’ where ‘id’= ‘name’
本文介绍了SQL的基础操作,包括查询、插入、更新和删除等基本语法,并解释了如何使用条件语句、聚合函数以及排序和限制结果集的方法。
795

被折叠的 条评论
为什么被折叠?



