select语句
select 简单查询语句
select * from table ; # 检索所有列
select distinct user from user ; # 去重查找
select * from dc limit 5 ; #检索前5行
select Top 5 * from table; #sqlserver和access中使用前5行
select * from table where rownum >=5 #oracle 数据库中使用
select * from table limit 5 offset 5 # 检索最后5行数据
排序检索
-
排序数据
select * from table order by name # 按照一个列排序 -
按照多个列排序
select id,name,age from user order by id,name -
按照位置排序
select id,name,age from user order by 2,3 # 先2(name)排序,然后3(age)排序 -
指定方向排序
select id,name,age from user order by age desc,name
数据过滤
-
使用where 语句
select id,name,age from user where name='prsa' 注意:当order by 和where 一起使用时,应该讲order 放在后边 -
组合where子句
-
and 操作符
select * from user where creatime >=2017-08-08 and price <50 -
or操作符
select * from user where name=ps or name = fl -
求值顺序
select * from user where (name='ps'or name='fl')and age>10 -
in 操作符
select * from t_user where username in ('admin','YL') in 和or 筛选结果一样 in的语法更加清楚直观 在与and和or组合是,求值顺序容易管理,比or执行的更快-
not操作符
select * from t_user where not username='admin'
select * from t_user where user !='admin'
-
-

浙公网安备 33010602011771号