INTRODUCTION TO SQL Chapter 1 - 3. 1. SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the.

Slides:



Advertisements
Similar presentations
WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
Advertisements

Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Structured Query Language Part I Chapter Three CIS 218.
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Using Single-Row Functions to Customize Output
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
Oracle Database Administration Lecture 3  Transactions  SQL Language: Additional information  SQL Language: Analytic Functions.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
SQL (DDL & DML Commands)
Single Row Functions Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number, date, general and conversion.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
SQL Oracle PL/SQL. Select SELECT column1, column2,...columnN FROM table_name WHERE condition; SELECT column1, column2,...columnN FROM table_name WHERE.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Conversion Functions.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 Creating and Maintaining Database Objects Part 1 Database Systems.
Introduction to Access Chapter 13 pages 1-4. What is a database??? Related information is stored in databases  All SC student information is stored in.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
Soal Minggu 1 Pengenalan Basis Data Perintah Dasar SQL.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Single Row Functions. 3-2 Objectives Explain the various types of functions available in SQL. Explain the various types of functions available in SQL.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Single Row Functions Part I Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number and date SQL functions.
Pengenalan Basis Data Perintah Dasar SQL
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Restricting and Sorting Data
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Basic select statement
(SQL) Aggregating Data Using Group Functions
UJIAN SQL MODEL SOAL D.
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
Introduction To Structured Query Language (SQL)
Introduction To Structured Query Language (SQL)
Reporting Aggregated Data Using the Group Functions
Reporting Aggregated Data Using the Group Functions
The University of Akron College of Applied Science & Technology Dept
Reporting Aggregated Data Using the Group Functions
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Restricting and Sorting Data
Aggregating Data Using Group Functions
Presentation transcript:

INTRODUCTION TO SQL Chapter 1 - 3

1. SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the WHERE clause value you enter an underscore (_). Which result will this statement provide ? A. It will execute, but it will NOT retrieve any data. B. It will display information on all teachers where OBJECT_ID begins with ‘HST’. C. It will return a syntax error because the TO_CHAR function was NOT used in the WHERE clause. D. It will display information on all teachers whose SUBJECT_ID begins with ‘HST_’, regardless of the case in which the SUBJECT_ID in stored. TEACHER IDLAST_NAMEFIRST_NAMESUBJECT_ID 88TsuMingHST AMER 70SmithEllenHST INDIA 56JonesKarenHST_REVOL 58HannJeffHST_CURR 63HopewellMary ElizabethHST_RELIG

2. The STUDENT table contains these columns : ID_NUMBER (9) LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) ENROLL_DATE DATE Evaluate these two statements : 1. SELECT CONCAT(INITCAP(first_name), INITCAP(last_name)) FROM student WHERE enroll_date < ’31-DEC-2002’ ; 2. SELECT INITCAP(first_name) || initcap( last_name ) FROM student WHERE enroll_date < ’31-DEC-2002’ ; Which statement is true ? A. The two statement will display the same data. B. The two statement will NOT display the same data. C. One off the statement will fail because it contains a syntax error. D. The two statement will retrieve the same data, but the format of the display will differ

3. Evaluate this SELECT statement : SELECT description, cost FROM product ORDER BY cost, quality ; Which statements are true ? (Chose all that apply ) A. The PRODUCT_ID value for the first record display is 220. B. The PRODUCT_IDs value for the last two records displayed are 140 and 126. C. The DESCRIPTION value for the first records displayed is ‘C 2pk-battery’. D. The DESCRIPTION value for the first two record displayed is ‘AA 2pk-battery. E. No row with a PRODUCT_ID of 220 is displayed. IDDESCRIPTIONMANUFACTURER_IDQUALITYCOST 215AAA 6pk-batteryNF AA 2pk-batteryEL D 2pk-batteryOT C 2pk-batteryOT AAA 6pk-batteryOT AAA 8pk-batteryNF AA 2pk-batteryNF C 2pk-batteryEL

4. The ACCOUNT table contains these columns : ACCOUNT_ID NUMBER(12) NEW_BALANCE NUMBER(7,2) PREV_BALANCE NUMBER(7,2) FINANCE_CHARGE NUMBER(7,2) These are the desired results : 1. Display all accounts that have a new balance that is less than the previous balance. 2. Display all accounts that have a finance charge that less than $ Include accounts that have no finance charge. Evaluate this statement : SELECT account_id FROM account WHERE new_balence < prev_balence AND NVL(finance_charge, 0) < 25; What does the statement provide ? A. All the desired results. B. One of the desired results. C. Two of the desired results. D. None of the desired results.

5. Evalute this SQL statement : SELECT line_item_id, order_id, product_id FROM line_item; Which WHERE clause should you include to test the QUANTITY columns for null values ? A. WHERE quantity = NULL; B. WHERE quantity <> NULL; C. WHERE quantity != NULL; D. WHERE quantity IS NULL;

6. Which SELECT statement should you use to the limit the display of account information to those accounts whose finance charge is greater than $ A. SELECT account_id, new_balence, finance_charge FROM account WHERE finance_charge > 75.00; B. SELECT account_id, new_balence, finance_charge FROM account HAVING finance_charge > 75.00; C. SELECT account_id, new_balence, finance_charge FROM account WHERE finance_charge > GROUP BY finance_charge; D. SELECT account_id, new_balence, finance_charge FROM account GROUP BY finance_charge;

7. The teachers table contains these columns : ID NUMBER(9) Primary Key LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) SUBJECT_ID NUMBER(9) Which query should you use to display only the full name of each teacher along with the identification number of the subject they are responsible for teaching ? A. SELECT * FROM teacher; B. SELECT last_name, subject_id FROM teacher; C. SELECT last_name, first_name, id FROM teacher; D. SELECT last_name, first_name, subject_id FROM teacher;

8. A new standard has been adopted in your department that all codes that contain only 3 characters must have a dash(-) and two character values appended to them. Which function can be used in your query to restrict the data displayed to only those codes containing 3 characters ? A. RPAD B. LENGTH C. SUBSTR D. REPLACE

9. For which task would you use the WHERE clause in a SELECT statement ? A. To compare PRODUCT_ID values to B. To designate the ORDER table location. C. To display only unique PRODUCT_ID values. D. To restrict the rows returned by a GROUP BY clause.

10. You query the database with this SQL statement : SELECT id_number, NVL(100/quality, 0) FROM product; Which SQL SELECT statement capabilities are achieved when this statements is executed ? A. Selection only. B. Projection only. C. Selection and projection only. D. Projection, selection and joining.

11. You must display the order number, line item number, product identification number and quantity of each item where the quantity ranges from 10 through 100. The order numbers must be in the range of 1500 through The results must be sorted by order number from lowest to highest and then further sorted by quality from highest to lowest. Which statements should you use to display the disired result ? A.SELECT order_id, line_item_id, product_id, quantity FROM line_item WHERE quantity BETWEEN 9 AND 101 AND order_id BETWEEN 1500 AND 1575 ORDER BY order_id DESc, quality DESC; B. SELECT order_id, line_item_id, product_id, quantity FROM line_item WHERE (quantity > 10 AND quantity < 100) AND order_id BETWEEN 1500 AND 1575 ORDER BY order_id DESc, quality DESC; C. SELECT order_id, line_item_id, product_id, quantity FROM line_item WHERE (quantity > 9 OR quantity < 101) AND order_id BETWEEN 1500 AND 1575 ORDER BY order_id DESc, quality DESC; D. SELECT order_id, line_item_id, product_id, quantity FROM line_item WHERE quantity BETWEEN 10 AND 100 AND order_id BETWEEN 1500 AND 1575 ORDER BY order_id DESc, quantity DESC;

12. Which statement concerning SQL function is true ? A. All date functions return DATE data type values B. Character functions can return character or number values. C. Single-row functions can only be used in SELECT and WHERE clauses. D. Conversion functions convert a column definition from one data type to another data type.

13. You query the database with this SQL statements : SELECT description FROM product ORDER BY manufacturer_id, quantity ASC What is the ID_NUMBER of the first value displayed ? A. C 2pk-battery. B. D 2pk-battery. C. AA 2pk-battery. D. AAA 6pk-battery. ID_NUMBERDESCRIPTIONMANUFACTURER_IDQUANTITYCOST 215AAA 6pk-batteryNF AA 2pk-batteryEL D 2 pk-batteryOT C 2pk-batteryOT AAA 6pk-batteryOT AAA 8pk-batteryNF AA 2pk-batteryNF C 2pk-batteryEL

14. Which SELECT statement will return a numeric value ? A. SELECT (14 + enroll_date) * 9 FROM student. B. SELECT (SYSDATE – enroll_date) * 9 FROM student. C. SELECT SYSDATE – enroll_date + TO_DATE(’29–MAY–02’) FROM student. D. SELECT (SYSDATE – enroll_date) + TO_DATE(’29–MAY–02’) FROM student.

15. Seniority is based on the number of years a student has been enrolled at the university. You must create a report that displays each student’s name, id number, and the number of years enrolled. The years enrolled must be rounded to a whole number, based on the number of months from the date enrolled until today. which statements produces the required result ? A. SELECT first_name||’,’||last_name “Student Name”,id ”id”, enroll_date, ROUND(SYSDATE) – ROUND(enroll_date) “Seniority” FROM student; B. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, ROUND((SYSDATE) – ROUND(enroll_date)) /12 “Seniority” FROM student; C. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, TRUNC(SYSDATE,’YY’) – TRUNC(enroll_date,’YY’) “Seniority” FROM student; D. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, ROUND(MONTHS_BETWEEN(SYSDATE,enroll_date)/12) ROUND(enroll_date) “Seniority” FROM student;

16. The EMPLOYEE table contains these columns : EMP_ID NUMBER(9) LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) COMM_PCT NUMBER(2) You need to display the commission percentage for each employee followed by a percent sign(%), if an employee does not receive a commission, the output should display ‘No Comm’ Employee commissions do not exceed 20 percent. Which statement should you use to achieve these result ? A. SELECT emp_id, last_name, NVL(comm_pct||’%’,’no Comm) FROM employee; B. SELECT emp_id, last_name, NVL(TO_CHAR(comm_pct||’%) ’No Comm’) FROM employee; C. SELECT emp_id, last_name, RPAD(NVL(TO_CHAR(comm_pct), ’No Comm 3 ‘ %’) FROM employee; D. None of the statements return the desired results.

17. You query the database with this SQL statement : SELECT * FROM transaction; For which purpose was this statement created ? A. To insert data into the TRANSACTION table. B. To view data into the TRANSACTION table. C. To review the structure of the TRANSACTION table. D. To delete selected data from the TRANSACTION table.

18. Which three statements concerning explicit data type conversion are true. (Chose three) A. A number value may be converted to a date value using the TO_DATE function. B. A date value may be converted to a number value using the TO_NUMBER function. C. A character value may be converted to a date value using the TO_DATE function. D. A date value may be converted to a character using the TO_DATE function. E. A date value may be converted to a character using the TO_CHAR function. F. A number value may be converted to a character string using the TO_CHAR function. G. A number value may be converted to a character string using the TO_NUMBER function.

19. Which SQL SELECT statement performs a projection, a selection, and join when executed ? A. SELECT id_number, manufacturer_id FROM product ORDER BY manufacturer_id, id_number; B. SELECT id_number, manufacturer_id FROM product WHERE manufacturer_id =‘NF 10032’; C. SELECT id_number, manufacturer_id FROM manufacturer AND manufacturer_id =‘NF 10032’ ORDER BY city; D. SELECT p.id_number, m.manufacturer_id, m.city FROM product p, manufacturer m WHERE p.manufacturer_id = m.manufacturer_id AND m.manufacturer_id =‘NF 10032’;