Introduction to sql
This presentation is the property of its rightful owner.
Sponsored Links
1 / 20

INTRODUCTION TO SQL PowerPoint PPT Presentation


  • 78 Views
  • Uploaded on
  • Presentation posted in: General

INTRODUCTION TO SQL. Chapter 1 - 3. 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 ?

Download Presentation

INTRODUCTION TO SQL

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to sql

INTRODUCTION TO SQL

Chapter 1 - 3


Introduction to sql

  • 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 ?

    • It will execute, but it will NOT retrieve any data.

    • It will display information on all teachers where OBJECT_ID begins with ‘HST’.

    • It will return a syntax error because the TO_CHAR function was NOT used in the WHERE clause .

    • 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


Introduction to sql

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 ?

  • The two statement will display the same data.

  • The two statement will NOT display the same data.

  • One off the statement will fail because it contains a syntax error.

  • The two statement will retrieve the same data, but the format of the display will differ


Introduction to sql

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 .


Introduction to sql

  • 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 $25.00.

    3. 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.


Introduction to sql

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;


Introduction to sql

  • Which SELECT statement should you use to the limit the display of account information to those accounts whose finance charge is greater than $75.00.

    • SELECT account_id, new_balence, finance_charge

      FROM account

      WHERE finance_charge > 75.00;

    • SELECT account_id, new_balence, finance_charge

      FROM account

      HAVING finance_charge > 75.00;

    • SELECT account_id, new_balence, finance_charge

      FROM account

      WHERE finance_charge > 75.00

      GROUP BY finance_charge;

    • SELECT account_id, new_balence, finance_charge

      FROM account

      GROUP BY finance_charge;


Introduction to sql

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;


Introduction to sql

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


Introduction to sql

9. For which task would you use the WHERE clause in a SELECT statement ?

A. To compare PRODUCT_ID values to 7382.

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.


Introduction to sql

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.


Introduction to sql

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 1575. 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 ?

  • 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;

  • 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;


Introduction to sql

12. Which statement concerning SQL function is true ?

  • All date functions return DATE data type values

  • Character functions can return character or number values.

  • Single-row functions can only be used in SELECT and WHERE clauses.

  • Conversion functions convert a column definition from one data type to another data type.


Introduction to sql

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.


Introduction to sql

14. Which SELECT statement will return a numeric value ?

  • SELECT (14 + enroll_date) + 30.5 * 9

    FROM student.

  • SELECT (SYSDATE – enroll_date) + 30.5 * 9

    FROM student.

  • SELECT SYSDATE – enroll_date + TO_DATE(’29–MAY–02’)

    FROM student.

  • SELECT (SYSDATE – enroll_date) + TO_DATE(’29–MAY–02’)

    FROM student.


Introduction to sql

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;


Introduction to sql

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.


Introduction to sql

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.


Introduction to sql

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.


Introduction to sql

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’;


  • Login