幾條簡(jiǎn)單而實(shí)用的SQL語(yǔ)句
幾條簡(jiǎn)單而且實(shí)用的SQL語(yǔ)言:
1. 選出每X-Y條記錄(按某個(gè)條件排序)
select top (y-x) * from (select top y * from table order by id) a order by id desc
2. 先出符合打件的記錄數(shù)
select conunt(*) from table where
3. 選取***ID號(hào)
select max(ID) from table
select top 1 id from table order by id desc
4. 按字段1統(tǒng)計(jì)字段2
select count(字段2) from table group by 字段1
select sum(字段2) from table group by 字段1
5. 選取不重復(fù)記錄
select distinct 字段 from table
【編輯推薦】