Slide 1 Chapter 2 Introduction to Structured Query Language (SQL) ‏

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

SQL CSET 3300.
M ATH IN SQL. 222 A GGREGATION O PERATORS Operators on sets of tuples. Significant extension of relational algebra. SUM ( [DISTINCT] A): the sum of all.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Structured Query Language Part I Chapter Three CIS 218.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
SQL Intermediate Workshop Authored by Jay Mussan-Levy.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Download three SQL script files from wiki page.
SQL – Logical Operators and aggregation Chapter 3.2 V3.0 Napier University Dr Gordon Russell.
1 SELECT statement. 2 Sample database Supplier Part supplies (0,n) colour s# snamep# pname amount citydob price qualitydate.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Chapter 3 Single-Table Queries
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 11-1 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server.
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Information Resource Engineering SQL4. Recap - Ordering Output  Usually, the order of rows returned in a query result is undefined.  The ORDER BY clause.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Structured Query Language SQL Unit 2 An Introduction to Organizing and Retrieving Data with SQL.
Selecting Data Database Administration Fundamentals LESSON 3.1a.
ORDER BY clause in SELECT command: Normally, the result of the query will not be in ordered format. If we want to get the result of the query in specific.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
 SAP AG 2003 Queries Alerts Management Content Queries and Alerts Management.
MIS2502: Data Analytics SQL – Getting Information Out of a Database.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Rules of Precedence The rules of precedence determine the order in which expressions are evaluated and calculated. The next table lists the default order.
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.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Database Design lecture 3_2 Slide 1 Database Design Lecture 3_2 Data Manipulation in SQL Simple SQL queries References: Text Chapter 8 Oracle SQL Manual.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
How to: SQL By: Sam Loch.
CS3220 Web and Internet Programming More SQL
CSIS 115 Database Design and Applications for Business
Writing Basic SQL SELECT Statements
The Database Exercises Fall, 2009.
JDBC.
SQL FUNDAMENTALS CDSE Days 2018.
MENAMPILKAN DATA DARI SATU TABEL (Chap 2)
Relational Databases The Relational Model.
Relational Databases The Relational Model.
MIS2502: Data Analytics SQL – Getting Information Out of a Database
Chapter 4 Summary Query.
Access: SQL Participation Project
Structured Query Language
Section 4 - Sorting/Functions
The University of Akron College of Applied Science & Technology Dept
MIS2502: Data Analytics SQL – Getting Information Out of a Database Part 1: Basic Queries Aaron Zhi Cheng
Presentation transcript:

Slide 1 Chapter 2 Introduction to Structured Query Language (SQL) ‏

Slide 2 Contents A. Storage Management Problem B. Solution

Slide 3  Due to manage the product in storage, Algo company needs a database which enables accessibility efficiently.  In their system, product has following information:  Product ID  Product name  Product type  Quantity which is currently available in storage  Product Price  Manufacturer  Each manufacturer has its ID, name and address.  Each manufacturer produces one or more products.  For example data of some products, prefer to next slide. A. Storage Management Problem

Slide 4  Example 1:  Product ID: PRO1  Product name: 512 MB DDRAM  Product type: RAM  Quantity: 10  Price: 30 $  Manufacturer ID: YUK  Manufacturer name: Yuki  Manufacturer address: Tokyo  Example 2:  Product ID: PRO2  Product name: 1 GB DDRAM  Product type: RAM  Quantity: 10  Price: 40 $  Manufacturer ID: YUK  Manufacturer name: Yuki  Manufacturer address: Tokyo

Slide 5 Display information of product name and quantity of all products. Display all information of all products. Display product type in product table. However, this result must be unique. Display all information of all products. Present result sorted by product name in descending order and then quantity in ascending order. Suppose there are some products which have type is RAM. Display information of all products which have product type is RAM. Suppose there are some products which have type is RAM. Display information of all products which have product type is RAM and quantity greater than 20.

Slide 6 Suppose there are some products which have type is RAM. Display information of all products which have product type is RAM or has quantity greater than 5. Suppose there are some products have name is “BOXDG” and 256MB DDRAM. Display information of all products which its names must contain in following set: [“BOXDG”, “256MB DDRAM”]. Suppose there are some products have name is “BOXDG” and 256MB DDRAM. Display information of product which its names must NOT contain in following set: [“BOXDG”,“256MB DDRAM”]. Display information of all products. Price of these product must be greater than or equals 30 and less than or equals 100. Suppose there are some products have name start with ‘GA’. Display information of product which its names must be started with ‘GA’ letters.

Slide 7 Suppose there are some products has name includes “G3” letters Display information of product. These product names must include ‘G3’ letters. Display number of all products in storage. Display sum of quantity of all products. Display Average of price of all products. Display Maximum price of all products. Display Minimum price of all products. Display value of each product in storage. The function of value is: VALUE = quantity * price

Slide 8 Display information of product name and product type. The format of this result is: “PRODUCT_NAME” is "PRODUCT_TYPE“ There are currently has two TYPE of product includes: Main board and RAM. Display the sum of quantity for each TYPE of product. Display product type which has Sum of quantity greater than 30. Suppose there are some products which were produced by Shiro manufacturer. Display name and manufacturer name of the product which its manufacturer is Shiro. Suppose there are some products which were produced by Shiro manufacturer and Sanno manufacturer. Display name of product which its manufacturer is Yuki and Sanno.

Slide 9 B. Solution 1.Logical Design 2.Physical Design 3.Creating DB and populating data into the DB 4.SQL Statement Solutions

Slide Logical Design Following the problem description and data examples, we have logical design of Product.

Slide Physical Design

Slide 12 Creating DB and populating data into the DB This is an exercise for you. The following are sample data.

Slide SQL Statement Solutions 4.1. Display PRODUCT NAME and QUANTITY Display all column in PRODUCT table Display unique PRODUCT TYPE Display PRODUCT NAME in descending order, QUANTITY in ascending order Display all products are RAM Display products are RAM and have quantity greater than Display products are RAM or have quantity greater than Display product has name is in set [“BOXDG”, “256MB DDRAM”] Display product has name is NOT in set [“BOXDG”, “256MB DDRAM”] Display product has 30 <= price <= Display product has name starts with “GA” letter Display product has name includes “G3” letter.

Slide SQL Statement Solutions Display number of rows in PRODUCT table Display SUM of quantity Display AVERAGE of price Display MAXIMUM of price Display MINIMUM of price Display Value of each product Display PRODUCT NAME, PRODUCT TYPE in format Display SUM of quantity of each product type Display SUM of quantity of each product type and Sum is greater than Display product of Shiro manufacturer Display product of Yuki and Sanno manufacturers.

Slide Display PRODUCT NAME and QUANTITY SELECT Name, Quantity FROM PRODUCTS;

Slide Display all column in PRODUCT table Selecting All Columns: The Asterisk (*) Keyword SELECT * FROM PRODUCTS;

Slide Display unique PRODUCT TYPE SELECT DISTINCT Type FROM PRODUCTS;

Slide Display PRODUCT NAME in descending order, QUANTITY in ascending order Sort Order: Ascending and Descending SELECT * FROM PRODUCTS ORDER BY Name DESC, Quantity ASC;

Slide Display all products are RAM SELECT * FROM PRODUCTS WHERE Type = 'RAM‘;

Slide Display products are RAM and have quantity greater than 20 SELECT * FROM PRODUCTS WHERE Type = 'RAM‘ AND Quantity > 20;

Slide Display products are RAM or have quantity greater than 5 SELECT * FROM PRODUCTS WHERE Type = 'RAM‘ OR Quantity > 5;

Slide Display product has name is in set [“BOXDG”, “256MB DDRAM”] SELECT * FROM PRODUCTS WHERE Name IN ('BOXDG‘, '256MB DDRAM');

Slide Display product has name is NOT in set [“BOXDG”, “256MB DDRAM”] SELECT * FROM PRODUCTS WHERE Name NOT IN ('BOXDG‘,'256MB DDRAM');

Slide Display product has 30 <= price <=100 Solution 1: SELECT * FROM PRODUCTS WHERE Price BETWEEN 30 AND 100; Solution 2: SELECT * FROM PRODUCTS WHERE Price >= 30 AND Price <= 100;

Slide Display product has name starts with “GA” letter SELECT * FROM PRODUCTS WHERE Name LIKE 'GA%';

Slide Display product has name includes “G3” letter SELECT * FROM PRODUCTS WHERE Name LIKE '%G3%';

Slide Display number of rows in PRODUCT table SELECT COUNT(*) as numRows FROM PRODUCTS;

Slide Display SUM of quantity SELECT SUM(Quantity) as sumQuantity FROM PRODUCTS;

Slide Display AVERAGE of price SELECT AVG(Price) as averagePrice FROM PRODUCTS;

Slide Display MAXIMUM of price SELECT MAX(Price) as maxPrice FROM PRODUCTS;

Slide Display MINIMUM of price SELECT MIN(Price) as minPrice FROM PRODUCTS;

Slide Display Value of each product Note: VALUE = quantity * price SELECT Name, Q uantity * Price as Value FROM PRODUCTS;

Slide Display PRODUCT NAME, PRODUCT TYPE in format SELECT Name + ' is ' + Type as detailName FROM PRODUCTS;

Slide Display SUM of quantity of each PRODUCT TYPE SELECT Type, SUM(Quantity) as totalQuantity FROM PRODUCTS GROUP BY Type;

Slide Display SUM of quantity of each PRODUCT TYPE and Sum is greater than 30 SELECT Type, SUM(Quantity) as totalQuantity FROM PRODUCTS GROUP BY Type HAVING SUM(Quantity) > 30;

Slide Display product of Shiro manufacturer SELECT Products.Name as ProductName, Manufacturers.Name as ManufacturerName FROM PRODUCTS, MANUFACTURERS WHERE Products.Man_ID = Manufacturers.Man_ID AND Manufacturers.Name = 'Shiro‘;

Slide Display product of Yuki and Sanno manufacturers Solution 1: SELECT Name FROM PRODUCTS WHERE Man_ID IN (SELECT Man_ID FROM MANUFACTURERS WHERE Name IN ('Sanno', 'Yuki')); Solution 2: SELECT P.Name FROM PRODUCTS P, MANUFACTURERS M WHERE P.Man_ID = M.Man_ID AND M.Name IN ('Sanno', 'Yuki');

Slide 38 References  Database Processing – Chapter 2 Fundamentals, Design and Implementation David M. Kroenke

Slide 39