資源描述:
《sql中as的用法和一些經(jīng)典的sql語句》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、sql中as的用法和一些經(jīng)典的sql語句2008-08-2121:55總結(jié)一些工作中用到或碰到的SQL語句,希望能與大家分享,同時(shí)也希望大家能提供更多的精妙SQL語句.....1、deletetable1from(selectfromtable2)ast2wheretable1.id=t2.id2、truncatetabletable1(不在事務(wù)日志中做記錄,比deletetable快,但不能激活觸發(fā)器)3、updatetable1setcolumn=column+1whereid=(selectidfromtable2)4、updatetable1setcolumn=column+
2、1fromtable1,table2wheretable1.id=table2.id5、selecttopn[Percent]fromtable1'輸出百分比記錄6、selectid,column1column2ascolumnfromtable1'可算明白as的用法了7、selectfromtable1wherecolumn1like'SQL#_G_O'escape'#''單匹配8、selecttable1.idfromtable1wherenotexists(selecttable2.idfromtable2wheretable1.id=table2.id)'這個(gè)應(yīng)該比notin
3、快一些9、selecttable1.idfromtable1,table2wheretable1.id<>table2.id'看復(fù)合查詢機(jī)制10、selecttable1.idfromtable1,table2,(selectidfromtable3)ast3wheretable1.id=table2.idandtable2.id=t3.id'有些類似[1]了......11、selectfromtable1wherecolumn1like'[A]%'orlike'[^B]%'12、select@column1=column1fromtable1;select@column1asco
4、lumn1'存儲到自定義變量13、selectfromtable1wherecontains(column1,'char1orchar2')'全文索引14、selectfromtable1wherecontains(column1,'前有near中有near后有')15、selectfromtable1wherecontains(column1,'formsof(inflectional,go)')'派生16、selectfromtable1wherecontains(description,'isabout(appleweight(.9),boyweight(.8),chinawe
5、ight(.7))')'權(quán)重17、selectfromtable1wherefreetext(column1,'char')'僅支持文字不支持表達(dá)式搜索18、insertintotable1selectcolumn1,count(column1)fromtable2groupbycolumn1'統(tǒng)計(jì)-----------------------------------------------------------------------------------------1說明:復(fù)制表(只復(fù)制結(jié)構(gòu),源表名:a新表名:b)SQL:selectintobfromawhere1<>12說
6、明:拷貝表(拷貝數(shù)據(jù),源表名:a目標(biāo)表名:b)SQL:insertintob(a,b,c)selectd,e,ffromb;3說明:顯示文章、提交人和最后回復(fù)時(shí)間SQL:selecta.title,a.username,b.adddatefromtablea,(selectmax(adddate)adddatefromtablewheretable.title=a.title)b4說明:外連接查詢(表名1:a表名2:b)SQL:selecta.a,a.b,a.c,b.c,b.d,b.ffromaLEFTOUTJOINbONa.a=b.c5說明:日程安排提前五分鐘提醒SQL:???se
7、lectfrom日程安排wheredatediff('minute',f開始時(shí)間,getdate())>56說明:兩張關(guān)聯(lián)表,刪除主表中已經(jīng)在副表中沒有的信息SQL:??deletefrominfowherenotexists(selectfrominfobzwhereinfo.infid=infobz.infid)7說明:從數(shù)據(jù)庫中去一年的各單位電話費(fèi)統(tǒng)計(jì)(電話費(fèi)定額和電話費(fèi)清單兩個(gè)表來源)SQL:SELECTa.userper,a.tel,a.stan