资源描述:
《[SAS课件] 斯坦福大学sas教学课件SAS_SQL1.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、IntroductionTheStructuredQueryLanguage(SQL)isastandardizedlanguageusedtoretrieveandupdatedatastoredinrelationaltables(ordatabases).WhencodinginSQL,theuserisnotrequiredtoknowthephysicalattributesofthetablesuchasdatalocationandtype.SQLisnonprocedural.Thepur
2、poseistoallowtheprogrammertofocusonwhatdatashouldbeselectedandnothowtoselectthedata.ThemethodofretrievalisdeterminedbytheSQLoptimizer,notbytheuser.Whatisatable?Atableisatwodimensionalrepresentationofdataconsistingofcolumnsandrows.IntheSQLprocedureatableca
3、nbeaSASdataset,SASdataview,ortablefromaRDBMS.Tablesarelogicallyrelatedbyvaluessuchasakeycolumn.RelationalTablesInSQLtablesarelogicallyrelatedbyakeycolumnorcolumns.SimpleQueriesIwouldliketoselectlastname,department,andsalaryfromtheemployeetablewheretheempl
4、oyee'ssalaryisgreaterthan35,000.Howwouldthisquery(request)lookinSQL?SELECTLASTNAME,DEPARTMENT,SALARYFROMCLASS.EMPLOYWHERESALARYGT35000Aqueryismerelyarequestforinformationfromatableortables.Thequeryresultistypicallyareportbutcanalsobeanothertable.BasicSynt
5、axPROCSQLStatements(clauses)intheSQLprocedurearenotseparatedbysemicolons,theentirequeryisterminatedwithasemicolon.ItemsinanSQLstatementareseparatedbyacomma.Thereisarequiredorderofstatementsinaquery.OneSQLprocedurecancontainmanyqueriesandaquerycanreference
6、theresultsfrompreviousqueries.TheSQLprocedurecanbeterminatedwithaQUITstatement,RUNstatementshavenoeffect.ExampleIwouldliketoselectthesocialsecuritynumber,salaryandbonus(columns)forallemployees(rows)fromtheemployeetableLIBNAMECLASS'C:CYDATA';PROCSQL;SELEC
7、TSSN,SALARY,BONUSFROMCLASS.EMPLOYEE;SelectingRowswithaWHEREClauseExample:Iwouldliketoselectthesocialsecuritynumber,salaryandbonus(columns)fromtheemployeetablewheretheemployeeisindepartmentGIOandhasasalarylessthat35,000.PROCSQL;SELECTSSN,SALARY,BONUSFROMC
8、LASS.EMPLOYEEWHEREDEPT='GIO'ANDSALARYLT35000;QUIT;WHEREClauseOperatorsTheWHEREclausesupportsmanycomparisonoperators.ItalsosupportslogicalNOTsandAND/ORtocreatecompoundexpressions.Standardcomparisonoperators:Specialop