几条简单而实用的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

【编辑推荐】

  1. 精简语句吧,让你的MySQL更有效
  2. Sql语句优化注意
  3. SQL面试题
  4. SQL语句的22条法宝
  5. 写SQL必须必须要遵循的原则
THE END