Pengenalan Basis Data Perintah Dasar SQL

Slides:



Advertisements
Similar presentations
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Advertisements

Virtual training week 4 structured query language (SQL)
Group functions cannot be used in the WHERE clause: SELECT type_code FROM d_songs WHERE SUM (duration) = 100; (this will give an error)
SQL Review Sections 1 - SQL and other basic statements.
LECTURE 10.  Group functions operate on sets of rows to give one result per group.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
1 Lecture 3: Subqueries DCO11310 Database Systems and Design By Rose Chang.
The SQL Query Language DML1 The SQL Query Language DML Odds and Ends.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
SQL Joins.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Database Programming Sections 4 – Joins. Marge Hohly2 Overview  Oracle Proprietary Joins (8i and prior): Cartesian Product Equijoin Non-equijoin Outer.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
INTRODUCTION TO SQL Chapter SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Subqueries.
Soal Minggu 1 Pengenalan Basis Data Perintah Dasar SQL.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
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.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Using Subqueries to Solve Queries
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Aggregating Data Using Group Functions
Basic select statement
ATS Application Programming: Java Programming
Manipulating Data.
LESSON Database Administration Fundamentals Inserting Data.
Using the Set Operators
Using Subqueries to Solve Queries
Writing Basic SQL SELECT Statements
(SQL) Aggregating Data Using Group Functions
Using the Set Operators
Aggregating Data Using Group Functions
UJIAN SQL MODEL SOAL D.
Restricting and Sorting Data
Chapter 2 Views.
“Manipulating Data” Lecture 6.
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
Database Processing: David M. Kroenke’s Chapter Seven:
Database systems Lecture 3 – SQL + CRUD
“Manipulating Data” Lecture 6.
Manipulating Data.
Using Subqueries to Solve Queries
Writing Basic SQL SELECT Statements
Chapter 2 Views.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Using CASE Value expression
Reporting Aggregated Data Using the Group Functions
Contents Preface I Introduction Lesson Objectives I-2
Using Subqueries to Solve Queries
Reporting Aggregated Data Using the Group Functions
Using Subqueries to Solve Queries
Using the Set Operators
Reporting Aggregated Data Using the Group Functions
Subqueries Schedule: Timing Topic 25 minutes Lecture
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Aggregating Data Using Group Functions
Presentation transcript:

Pengenalan Basis Data Perintah Dasar SQL Soal Minggu 1 Pengenalan Basis Data Perintah Dasar SQL

1. Evaluate this SQL statement : SELECT c.customer_id, o.order_id, o.order_date, p.product_name FROM customer c, curr_order o, product p WHERE customer.customer_id = curr_order. customer_id AND o.product_id = p.product_id ORDER BY o.order_amount; This statement fails when executed. Which change will correct the problem? Use the table name in the ORDER BY clause. Remove the table aliases from the WHERE clause. Include the ORDER_AMOUNT column in the SELECT list. Use the table aliases instead of the table names in the WHERE clause. Remove the table alias from the ORDER BY clauses and use only the column name.

which statements produces the required result ? 2. 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 ? SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, TRUNC(SYSDATE,’YY’) – TRUNC(enroll_date,’YY’) “Seniority” FROM student; c. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, ROUND(MONTHS_BETWEEN(SYSDATE,enroll_date)/12) “Seniority” FROM student d. SELECT first_name||’,’||last_name “Student Name”, id ”id”, enroll_date, ROUND(SYSDATE) – ROUND(enroll_date) “Seniority” e. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, (ROUND((SYSDATE) – ROUND(enroll_date)) /12 “Seniority” FROM student

3. The EVENT table contains these columns: EVENT_ID NUMBER EVENT_NAME VARCHAR2(30) EVENT_DESC VARCHAR2(100) EVENT_TYPE NUMBER LOCATION_ID NUMBER You have been asked to provide a report of the number of different event types at each location. Which SELECT statement will produce the desired result? SELECT UNIQUE(location_id), COUNT(event_type) FROM event GROUP BY location_id; SELECT location_id, COUNT(DISTINCT event_type) FROM event GROUP BY location_id; SELECT location_id, MAX(DISTINCT event_type) FROM event GROUP BY location_id SELECT DISTINCT(event_type) FROM event GROUP BY location_id; SELECT COUNT(*), DISTINCT(location_id) FROM event;

4. Evaluate this SQL statement: SELECT supplier_id, AVG(cost) FROM product WHERE AVG(list_price) > 60.00 GROUP BY supplier_id ORDER BY AVG(cost) DESC; Which clause will cause an error? SELECT ORDER BY WHERE GROUP BY

5. Which statement type would be used to remove transactions more than one year old from the TRX table ? DCL DDL DML DRL TCL

6. Which Database Objects not incluided in a Oracle Database Table Sequence Constraint Synonym Index

7. Evaluate this SQL statement : SELECT c.customer_id, o.order_id, o.order_date, p.product_name FROM customers c, curr_order o, product p WHERE customer.customer_id = curr_order. customer_id AND o.product_id = p.product_id ORDER BY o.order_amount; This statement fails when executed. Which changne will corect the problem? Use the table name in the ORDER BY clause Remove the table aliases from the WHERE clause Include the ORDER_AMOUNT column in the SELECT list. Use the table aliases instead of the table names in the WHERE clause Remove the table alias from the ORDER BY clauses and use only the column name

8. The EVENT table contains these columns: EVENT_ID NUMBER EVENT_NAME VARCHAR2(30) EVENT_DESC VARCHAR2(100) EVENT_TYPE NUMBER LOCATION_ID NUMBER You have been asked to provide a report of the number of different event types at each location. Which SELECT statement will produce the desired result? SELECT UNIQUE(location_id), COUNT(event_type) FROM event GROUP BY location_id; SELECT COUNT(*), DISTINCT(location_id) FROM event; SELECT DISTINCT(event_type) FROM event GROUP BY location_id; SELECT location_id, COUNT(DISTINCT event_type) FROM event GROUP BY location_id; SELECT location_id, MAX(DISTINCT event_type) FROM event GROUP BY location_id;

9. Evaluate this SQL statement SELECT supplier_id, AVG(cost) FROM product WHERE AVG(list_price) > 60.00 GROUP BY supplier_id ORDER BY AVG(cost) DESC; Which clause will cause an error? SELECT WHERE GROUP BY ORDER BY

10. Evaluate this SELECT statement: SELECT employee_id, name FROM employee WHERE employee_id NOT IN (SELECT employee_id FROM employee WHERE department_id = 30 AND job = ‘CLERK’); What would happen if the inner query returned a NULL values? A syntax error would be returned No rows would beselected from the employee tables All the EMPLOYEE_ID and NAME values in the EMPLOYEE table would be displayed Only the rows with EMPLOYEE_ID values equal to NULL would be included in the results

11. You query the database with the SELECT statement: SELECT COUNT(instructor_id) FROM class; Which value is displayed? 2 3 4 5 The statement will NOT execute succesfully CLASS_ID CLASS_NAME HOURS_CREDIT INSTRUCTOR_ID 1 Intro. To Acc. 3 4 2 Computer Basic Tax Accounting American History 5 Basic Engineering