全球旧事资料 分类
from表名orderby排序字段desca表名bwhereb主键字段a主键字段orderbya排序字段具体实现:关于数据库分页:
declarestarti
te
di
tsql
varchar600setsql’selecttop’stre
dstart1’fromTwhererid
oti
selecttop’strstr1’RidfromTwhereRid1’execsp_executesqlsql
注意:在top后不能直接跟一个变量,所以在实际应用中只有这样的进行特殊的处理。Rid为一个标识列,如果top后还有具体的字段,这样做是非常有好处
f的。因为这样可以避免top的字段如果是逻辑索引的,查询的结果后实际表中的不一致(逻辑索引中的数据有可能和数据表中的不一致,而查询时如果处在索引则首先查询索引)
14、说明:前10条记录selecttop10formtable1where范围15、说明:选择在每一组b值相同的数据中对应的a最大的记录的所有信息类似这样的用法可以用于论坛每月排行榜每月热销产品分析按科目成绩排名等等selectabcfromtable
ametawhereaselectmaxafromtable
ametbwheretbbtab16、说明:包括所有在TableA中但不在TableB和TableC中的行并消除所有重复行而派生出一个结果表selectafromtableAexceptselectafromtableBexceptselectafromtableC17、说明:随机取出10条数据selecttop10fromtable
ameorderby
ewid18、说明:随机选择记录select
ewid19、说明:删除重复记录1deletefromtable
amewhereid
oti
selectmaxidfromtable
amegroupbycol1col22selectdisti
cti
totempfromtable
ame
deletefromtable
amei
serti
totable
ameselectfromtemp评价:这种操作牵连大量的数据的移动,这种做法不适合大容量但数据操作
f3例如:在一个外部表中导入数据,由于某些原因第一次只导入了一部分,但很难判断具体位置,这样只有在下一次全部导入,这样也就产生好多重复的字段,怎样删除重复字段altertabletable
ame添加一个自增列addcolum
_bi
tide
tity11
deletefromtable
amewherecolum
_b
oti
selectmaxcolum
_bfromtable
amegroupbycolum
1colum
2altertabletable
amedropcolum
colum
_b20、说明:列出数据库里所有的表名select
amefromsysobjectswheretypeUU代表用户21、说明:列出表里的所有的列名select
amefromsyscolum
swhereidobject_idTableName22、说明:列示type、ve
der、pcs字段,以type字段排列,case可以方便地实现多重选择,类似select中的case。selecttypesumcaseve
derwhe
Athe
pcselse0e
dsumcaseve
derwhe
Cthe
pcselse0e
dsumcaseve
derwhe
Bthe
pcselse0e
dFROMtable
amegroupbytype显示结果:typeve
derpcs电脑A1电脑A1光盘B2光盘A2
f手机B3手机C3
23、说明:初始化表r
好听全球资料 返回顶部