版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Retrieving Data Using the SQL SELECT StatementObjectivesAfter completing this lesson, you should be able to do the following:List the capabilities of SQL SELECT statementsExecute a basic SELECT statementLesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statement
2、Column aliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandCapabilities of SQL SELECT StatementsSelectionProjectionTable 1Table 2Table 1Table 1JoinBasic SELECT StatementSELECT identifies the columns to be displayed.FROM
3、 identifies the table containing those columns.SELECT *|DISTINCT column|expression alias,.FROM table;Selecting All ColumnsSELECT *FROM departments;Selecting Specific ColumnsSELECT department_id, location_idFROM departments;Writing SQL StatementsSQL statements are not case sensitive.SQL statements ca
4、n be entered on one or more lines.Keywords cannot be abbreviated or split across lines.Clauses are usually placed on separate lines.Indents are used to enhance readability.In SQL Developer, SQL statements can be optionally terminated by a semicolon (;). Semicolons are required when you execute multi
5、ple SQL statements.In SQL*Plus, you are required to end each SQL statement with a semicolon (;).Column Heading DefaultsSQL Developer:Default heading alignment: Left-alignedDefault heading display: UppercaseSQL*Plus:Character and Date column headings are left-aligned.Number column headings are right-
6、aligned.Default heading display: UppercaseLesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statementColumn AliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandArithmetic Expression
7、sCreate expressions with number and date data by using arithmetic operators.Multiply*Divide/Subtract-Add+DescriptionOperatorSELECT last_name, salary, salary + 300FROM employees;Using Arithmetic OperatorsSELECT last_name, salary, 12*salary+100FROM employees;Operator PrecedenceSELECT last_name, salary
8、, 12*(salary+100)FROM employees;12注:题17 Defining a Null ValueNull is a value that is unavailable, unassigned, unknown, or inapplicable.Null is not the same as zero or a blank space.SELECT last_name, job_id, salary, commission_pctFROM employees; SELECT last_name, 12*salary*commission_pctFROM employee
9、s;Null Values in Arithmetic ExpressionsArithmetic expressions containing a null value evaluate to null.Lesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statementColumn aliasesUse of concatenation operator, literal character strings, alternative quote operator,
10、and the DISTINCT keywordDESCRIBE commandDefining a Column AliasA column alias:Renames a column headingIs useful with calculationsImmediately follows the column name (There can also be the optional AS keyword between the column name and the alias.)Requires double quotation marks if it contains spaces
11、 or special characters, or if it is case-sensitive Using Column AliasesSELECT last_name Name , salary*12 Annual SalaryFROM employees;SELECT last_name AS name, commission_pct commFROM employees;注:题12、题15Lesson AgendaBasic SELECT StatementArithmetic Expressions and NULL values in SELECT statementColum
12、n AliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandConcatenation OperatorA concatenation operator:Links columns or character strings to other columnsIs represented by two vertical bars (|)Creates a resultant column t
13、hat is a character expressionSELECTlast_name|job_id AS EmployeesFROM employees;Literal Character StringsA literal is a character, a number, or a date that is included in the SELECT statement.Date and character literal values must be enclosed within single quotation marks.Each character string is out
14、put once for each row returned.Using Literal Character StringsSELECT last_name | is a |job_id AS Employee DetailsFROM employees;Alternative Quote (q) OperatorSpecify your own quotation mark delimiter.Select any delimiter.Increase readability and usability.SELECT department_name | q Departments Manag
15、er Id: | manager_id AS Department and Manager FROM departments;注:题13Duplicate RowsThe default display of queries is all rows, including duplicate rows.SELECT department_idFROM employees;SELECT DISTINCT department_idFROM employees;12注:题14Lesson AgendaBasic SELECT statementArithmetic expressions and N
16、ULL values in the SELECT statementColumn aliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandDisplaying the Table StructureUse the DESCRIBE command to display the structure of a table.Or, select the table in the Connect
17、ions tree and use the Columns tab to view the table structure.DESCRIBE tablenameUsing the DESCRIBE CommandDESCRIBE employees QuizIdentify the SELECT statements that execute successfully.SELECT first_name, last_name, job_id, salary*12 AS Yearly SalFROM employees; SELECT first_name, last_name, job_id,
18、 salary*12 yearly salFROM employees; SELECT first_name, last_name, job_id, salary AS yearly salFROM employees;SELECT first_name+last_name AS name, job_Id, salary*12 yearly salFROM employees;SummaryIn this lesson, you should have learned how to:Write a SELECT statement that:Returns all rows and columns from a tableReturns specified columns from a tableUses column aliases to disp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2027年山西大同师范高专单招职业技能考试模拟试卷【历年真题】附答案详解
- 2025-2026学年吉林省长春市汽车经济技术开发区第二实验联盟四下数学期中统考试题(含解析)
- 2027年怀化舞水职业学院高职单招职业适应性测试考试题库附参考答案详解(培优)
- 某饮料厂生产线管理准则
- 某家具厂工艺标准
- 2025年北京市密云县高职单招职业适应性测试考试题库附答案详解【综合卷】
- 2024年巴中巴河文旅职业学院高职单招职业适应性测试考试模拟试卷及参考答案详解(考试直接用)
- 2025-2026学年南宁市横县四年级数学下学期期中质量跟踪监视试题(含答案解析)
- 2025-2026学年南充市蓬安县数学三年级下学期期中调研试题含解析
- 2025年黄陵红色学院高职单招职业适应性测试考试题库及完整答案详解【考点梳理】
- 2026年城市地下综合管廊智能化改造实施方案
- 2026年山东省泰安市新泰市某国企招聘笔试备考题库及答案详解参考
- 2026年房地产估价师专业能力测试题集及答案解析
- 2026广东广州市暨南大学附属实验学校招聘教师6人考试备考试题及答案详解
- 2026年民法课后测试题及答案
- 2026年全国新高考1卷语文试卷(含答案及解析)
- 2026年小学四年级英语第二学期期末考试卷及答案(一)
- 教科版小学六年级科学上册全册教案
- 贵州出版集团必背资料汇 总招聘笔试考试题库
- 隧道通风计算公式
- 2025山西潞安化工集团招聘专科及以上学历生产操作岗位人员笔试历年备考题库附带答案详解
评论
0/150
提交评论