資源描述:
《SQL語(yǔ)法大全(個(gè)人筆記)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Sql指令üSelectStore_NameFromStore_InformationüSelectDistinctStore_NameFromStore_InformationüSelectStore_NameFromStore_InformationWhereSales>1000üSelectStore_NameFromStore_InformationWhereSales>1000Or(Sales<500AndSales>275)üSelect*FromStore_InformationWhereStore_NameIn('LosAngeles','SanDiego')
2、üSelect*FromStore_InformationWhereDateBetween'Jan-06-1999'And'Jan-10-1999'üSql中有兩個(gè)通配符:%(百分比符號(hào)):代表零個(gè)、一個(gè)、或數(shù)個(gè)字母。_(底線):代表剛好一個(gè)字母。通配符是與Like關(guān)鍵詞一起使用的üSelect*FromStore_InformationWhereStore_NameLike'%An%'üSelectStore_Name,Sales,DateFromStore_InformationOrderBySalesDescüAvg(平均)SelectAvg(Sales)FromSto
3、re_InformationüCount(計(jì)數(shù)):SelectCount(Store_Name)FromStore_InformationWhereStore_NameIsNotNullSelectCount(DistinctStore_Name)FromStore_InformationüMax(最大值)SelectMax(Sales)FromStore_InformationüMin(最小值)SelectMin(Sales)FromStore_InformationüSum(總合)SelectSum(Sales)FromStore_InformationüSelectSt
4、ore_Name,Sum(Sales)FromStore_InformationGroupByStore_NameüSelectStore_Name,Sum(Sales)FromStore_InformationGroupByStore_NameHavingSum(Sales)>1500ü別名:SelectA1.Store_NameStore,Sum(A1.Sales)"TotalSales"FromStore_InformationA1GroupByA1.Store_NameüAs:SelectA1.Store_NameStore,Sum(A1.Sales)As"Total
5、Sales"FromStore_InformationAsA1GroupByA1.Store_Nameü連接:SelectRegion_Name+''+Store_NameFromGeographyWhereStore_Name='Boston'üSubstr(Str,Pos,Len):由中的第位置開始,選出接下去的個(gè)字符。SelectSubstr(Store_Name,2,4)FromGeographyWhereStore_Name='SanDiego'üLtrim(字符串):將所有字符串起頭的空白移除。Rtrim(字符串):將所有字符串結(jié)尾的
6、空白移除。üLength(Str):找出Str字符串的長(zhǎng)度üReplace(Str1,Str2,Str3):在字符串Str1中,當(dāng)Str2出現(xiàn)時(shí),將其以Str3替代。SelectReplace(Region_Name,'Ast','Astern')FromGeography表格處理ü創(chuàng)建表格CreateTableCustomer(First_NameChar(50),Last_NameChar(50),AddressChar(50),CityChar(50),CountryChar(25),Birth_DateDate)ü非空CreateTableCustomer(SidIn
7、tegerNotNull,Last_NameVarchar(30)NotNull,First_NameVarchar(30))üUnique限制是保證一個(gè)字段中的所有數(shù)據(jù)都是有不一樣的值。CreateTableCustomer(SidIntegerUnique,Last_NameVarchar(30),First_NameVarchar(30))üCheck限制是保證一個(gè)字段中的所有數(shù)據(jù)都是符合某些條件。CreateTableCustomer(SidIntegerCheck(Sid>0),Last_Na