資源描述:
《SQL基本SELECT查詢(xún)語(yǔ)句_內(nèi)外連接.ppt》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Select查詢(xún)7/18/20211MicrosoftSQLServer2005SELECT語(yǔ)法總結(jié)SELECT*/字段名,字段名……FROM表名[WHERE條件表達(dá)式][GROUPBY分組的字段名][HAVING條件表達(dá)式][ORDERBY排序的字段名[ASC
2、DESC]]上述“[]”表示可選項(xiàng),“
3、”表示取其中之一。7/18/20212MicrosoftSQLServer2005簡(jiǎn)單Select查詢(xún)語(yǔ)法:SELECT字段1,字段2,…FROM表名SELECT*FROM表名SELECT字段1,字段2,…FROM表名WHERE查詢(xún)條件SELECT*FROM表名WHERE查詢(xún)條件簡(jiǎn)單的Trans
4、act-SQL查詢(xún)只包括選擇列表、FROM子句和WHERE子句。它們分別說(shuō)明所查詢(xún)列、查詢(xún)的表或視圖、以及搜索條件等。--------------------------------------------------------------------7/18/20213MicrosoftSQLServer2005簡(jiǎn)單Select查詢(xún)SELECTStuId,StuName,DeptId,SexFROMTb_StudentSELECT*FROMTb_Student7/18/20214MicrosoftSQLServer2005簡(jiǎn)單Select查詢(xún)SELECTStuId,StuName,Dept
5、Id,SexFROMTb_StudentWHERESex='F'SELECT*FROMTb_TeacherWHERESex='F'andDeptId='08'7/18/20215MicrosoftSQLServer2005WHERE子句使用的運(yùn)算符類(lèi)別運(yùn)算符說(shuō)明比較運(yùn)算符=、>、<、>=、<=、<>比較兩個(gè)表達(dá)式邏輯運(yùn)算符AND、OR、NOT組合兩個(gè)表達(dá)式的運(yùn)算結(jié)果或取反范圍運(yùn)算符BETWEEN、NOTBETWEEN查詢(xún)值是否在范圍內(nèi)列表運(yùn)算符IN、NOTIN查詢(xún)值是否屬于列表值之一字符匹配符LIKE、NOTLIKE字符串是否匹配未知值ISNULL、ISNOTNULL查詢(xún)值是否為NULL7/1
6、8/20216MicrosoftSQLServer2005比較運(yùn)算符和表達(dá)式運(yùn)算符含?義=等于>大于<小于>=大于等于<=小于等于<>不等于SELECT*FROMTb_StudentWHEREStuName<>'張三'SELECT*FROMTb_StudentWHERESex='F'7/18/20217MicrosoftSQLServer2005邏輯運(yùn)算符和表達(dá)式運(yùn)算符含?義AND如果兩個(gè)布爾表達(dá)式都為T(mén)RUE,那么就為T(mén)RUEOR如果兩個(gè)布爾表達(dá)式中的一個(gè)為T(mén)RUE,那么就為T(mén)RUENOT對(duì)任何其他布爾運(yùn)算符的值取反SELECT*FROMTb_StudentWHERESex='M'andSe
7、x='F'SELECT*FROMTb_StudentWHEREClassId='S040201101'andSex='F'SELECT*FROMTb_StudentWHERENOTSex='M'7/18/20218MicrosoftSQLServer2005范圍搜索運(yùn)算符和表達(dá)式SELECT*FROMTb_StudentWHEREAgeBETWEEN20TO22---------------------------------------------------------------------------------------SELECT*FROMTb_StudentWHEREAgeNO
8、TBETWEEN20TO22---------------------------------------------------------------------------------------SELECT*FROMTb_StudentWHEREAgeIN(20,21,22)---------------------------------------------------------------------------------------相當(dāng)于SELECT*FROMTb_StudentWHEREAge=20ORAge=21ORAge=22類(lèi)別運(yùn)算符說(shuō)明范圍運(yùn)算符BETWEEN、
9、NOTBETWEEN查詢(xún)值在范圍內(nèi)列表運(yùn)算符IN、NOTIN查詢(xún)值屬于列表值之一7/18/20219MicrosoftSQLServer2005模式匹配運(yùn)算符和表達(dá)式SELECT*FROMTb_StudentWHEREStuNameLIKE'張%'通配符說(shuō)明示例%匹配零個(gè)或多個(gè)字符的任意字符串。LIKE'%林%'姓名中包含有“林”的信息。_下劃線匹配任何單個(gè)字符。一個(gè)漢字只使用一個(gè)"_"表示LIK