几条简单而实用的SQL语句
几条简单而且实用的SQL语言:
1. 选出每X-Y条记录(按某个条件排序)
select top (y-x) * from (select top y * from table order by id) a order by id desc
2. 先出符合打件的记录数
select conunt(*) from table where
3. 选取***ID号
select max(ID) from table
select top 1 id from table order by id desc
4. 按字段1统计字段2
select count(字段2) from table group by 字段1
select sum(字段2) from table group by 字段1
5. 选取不重复记录
select distinct 字段 from table
【编辑推荐】
- 精简语句吧,让你的MySQL更有效
- Sql语句优化注意
- SQL面试题
- SQL语句的22条法宝
- 写SQL必须必须要遵循的原则
版权声明:
作者:后浪云
链接:https://www.idc.net/help/386577/
文章版权归作者所有,未经允许请勿转载。
THE END