sql中as的用法和一些经典的sql语句200808212155总结一些工作中用到或碰到的SQL语句,希望能与大家分享,同时也希望大家能提供更多的精妙SQL语句1、deletetable1fromselectfromtable2ast2wheretable1idt2id2、tru
catetabletable1不在事务日志中做记录,比deletetable快,但不能激活触发器3、updatetable1setcolum
colum
1whereidselectidfromtable24、updatetable1setcolum
colum
1fromtable1table2wheretable1idtable2id5、selecttop
Perce
tfromtable1输出百分比记录6、selectidcolum
1colum
2ascolum
fromtable1可算明白as的用法了7、selectfromtable1wherecolum
1likeSQL_G_Oescape单匹配8、selecttable1idfromtable1where
otexistsselecttable2idfromtable2wheretable1idtable2id这个应该比
oti
快一些9、selecttable1idfromtable1table2wheretable1idtable2id看复合查询机制10、selecttable1idfromtable1table2selectidfromtable3ast3wheretable1idtable2ida
dtable2idt3id有些类似1了11、selectfromtable1wherecolum
1likeAorlikeB12、selectcolum
1colum
1fromtable1selectcolum
1ascolum
1存储到自定义变量13、selectfromtable1whereco
tai
scolum
1char1orchar2全文索引14、selectfromtable1whereco
tai
scolum
1前有
ear中有
ear后有15、selectfromtable1whereco
tai
scolum
1formsofi
flectio
algo派生16、selectfromtable1whereco
tai
sdescriptio
isaboutappleweight9boyweight8chi
aweight7权重17、selectfromtable1wherefreetextcolum
1char仅支持文字不支持表达式搜索18、i
serti
totable1selectcolum
1cou
tcolum
1fromtable2groupbycolum
1统计1说明:复制表只复制结构源表名:a新表名:bSQLselecti
tobfromawhere112说明:拷贝表拷贝数据源表名:a目标表名:b
fSQLi
serti
tobabcselectdeffromb3说明:显示文章、提交人和最后回复时间SQLselectatitleauser
amebadddatefromtableaselectmaxadddateadddatefromtablewheretabletitleatitleb4说明:外连接查询表名1:a表名2:bSQLselectaaabacbcbdbffromaLEFTOUTJOINbONaabc5说明:日程安排提前五分钟提醒SQLselectfrom日程安排wheredatediffmi
utef开始时间getdate5
6说明:两张关联表,删除主表中已经在副表中没有的信息SQLdeletefromi
fowhere
otexistsselectfromi
fobzwherei
foi
fidi
fobzi
fid7说明:从数据库中去一年的各单位电话费统计电话费定额和电话费清单两个表来源)SQLSELECTauserperatelasta
dfeeTO_CHARatelfeedateyyyyAStelyearr