CS 3630 Database Design and Implementation. SQL Query Clause Select and From Select * From booking; select hotel_no, guest_no, room_no from booking; select.

Slides:



Advertisements
Similar presentations
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Advertisements

Chapter 4 Hotel (hotelno, hotelname, city)
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
1 Assignment 2 Relational Algebra Which tables? What operations? Common attributes? What result (attributes)? Syntax (Standard Notations and Symbols) –Product:
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
Chapter 6 SQL Homework.
Chapter 5 SQL Homework.
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.
Using SQL to create tables Ways of using Databases.
Project Phase I Phase II Due Monday, April 15 Groups 1.
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
Lecture 6 29/1/15. Number functions Number functions take numbers as input, change them, and output the results as numbers. 2.
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.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
SINGLE-ROW FUNCTIONS Lecture 9. SQL Functions Functions are very powerful feature of SQL and can be used to do the following:  Perform a calculation.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
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 queries ordering and grouping and joins
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL - DML. Data Manipulation Language(DML) Are used for managing data: –SELECT retrieve data from the a database –INSERT insert data into a table –UPDATE.
Oracle Command Spool Spool C:\temp\Lab9.lst Select Hotel_no, room_no, type, price From Room Order by Hotel_no; Spool Off.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Chapter 5 SQL: Data Manipulation Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
SQL introduction 2013.
Single Row Functions. Objectives –Use character, number, and date functions –Use conversion functions –Describe types of single row functions in SQL.
Structured Query Language
CS 3630 Database Design and Implementation. Joins -- For each booking, display the booking -- details with the room type and price Select B.*, rtype,
INTRODUCTION TO SQL Chapter SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the.
INF 280 Database Systems SQL:Join
Populating and Querying tables Insert, Update, Delete and View (DML)
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
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.
CS 3630 Database Design and Implementation. Base Table and View Base Table Stored on disk View Virtual table Records are not stored on disk Query is stored.
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
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.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
CS 3630 Database Design and Implementation. Joins -- For each booking, display the booking -- details with the room type and price Select B.*, rtype,
CS 3630 Database Design and Implementation. Joins Retrieve data from two or more tables Join Conditions PK and FK (Natural Join) Other attributes (Theta.
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.
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.
CS 3630 Database Design and Implementation
Assignment 2 Relational Algebra Which tables? What operations?
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Assignment 2.
SQL 101 3rd Session.
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Chapter 4 Summary Query.
CS 3630 Database Design and Implementation
Single-Row Functions Lecture 9.
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

CS 3630 Database Design and Implementation

SQL Query Clause Select and From Select * From booking; select hotel_no, guest_no, room_no from booking; select Distinct hotel_no, guest_no, room_no from booking; -- Remove duplicate records -- Unique also works 2

Oracle Command Column (Col) Column Hotel_no format A9 Col Hotel_No format a9 heading 'Hotel No' -- This also work col Hotel_no format a9 heading "Hotel No" -- to get leading decimal digits Column Price format $ heading 'Price/Night' -- to get leading 0s Column Price format $ heading 'Price/Night' Col Date_To format a16 heading 'Date of Leaving' Col Date_From format a16 heading 'Date of|Arrival' Select * from Room; Select * from Booking; Clear col 3

Clause Where Select * From Room Where RType = 'Single‘; -- Where clause to specify the condition -- Operators And/Or Select * From Room Where Price > 35 and RType = 'Single‘; -- Where Price > 35 or RType = 'Single' 4

Operator NOT (!) Select * From Room Where Price > 35 and RType != 'Family'; -- Where Price > 35 and Not (RType = 'Family‘) -- Where Price > 35 and NOT RType = 'Family‘ -- Not working: -- Where Price > 35 and !(RType = 'Family‘) 5

Operator NOT (!) Select * From Room Where Not (Price > 35 and RType = 'Family'); -- Not the same! Select * From Room Where Not Price > 35 and RType = 'Family'; --Where (Not Price > 35) and RType = 'Family'; --Where Price <= 35 and RType = 'Family'; 6

Operator Between Select * From Room Where Price between 30 and 45; -- Operator Between -- inclusive Select * From Room Where Price Not between 30 and 45; -- Where Not Price between 30 and 45; 7

Operator IN Select * From Room Where Price in (30, 40, 45); -- Same as -- Where Price = 30 or Price = 40 or Price = 45 Select * From Room Where Price Not in (30, 40, 45); -- Same as -- Where Not Price in (30, 40, 45); 8

Comparing Strings Operator Like and % Select * From guest Where guest_name = 'Mary Tregear' Where guest_name like 'M%'; -- All guests with name beginning with 'M‘ -- %: any string of zero or more chars 9

Operator Like and Char ‘_’ -- All records whose Fname has 'M' for 3rd position Select * From Guest Where guest_name like '__M%'; -- _: any single char 10

Null Value Select * From Guest Where Address = null; -- No row is selected -- null != null Select * From Guest Where Address is null; -- Some rows may be selected 11

Changing Headings -- use " " for heading -- Use ' ' for string -- With or without "AS" Select Guest_no, Guest_name as "Guest Name" From Guest; Select Guest_no, Guest_name "Guest Name" From Guest; Select Guest_no, Guest_name as GuestName From Guest; Select Guest_no, Guest_name GuestName From Guest; 12

Sorting the Result Select * From Room Order by Price desc; -- ASC is the default 13

Sorting the Result Select * From Room Order by Hotel_No, Price desc; -- Sorting first on Hotel_No (asc), -- then on Price (desc) -- ASC is the default 14

Sorting the Result Select Hotel_No, Room_No, RType From Room Order by Hotel_No, Price desc; -- Price may not be selected 15

Sorting the Result -- Can be used in Order by Select Guest_no, Guest_name as GuestName From Guest Order by GuestName; Select Guest_no, Guest_name as "Guest Name" From Guest Order by "Guest Name“; 16

Numeric Operators/Functions Select Hotel_No, Room_No, Price * 0.90 "Discount Price" From Room; -- Where Hotel_No = ‘H01'; -- operators: +, -, /, * -- functions: ceil, floor, mod, power, sign, sqrt -- With As 17

Character Functions Select Guest_Name || ' From ' || Address From Guest Where Address is not null; 18

Character Functions Lower Upper Initcap length replace -- Replace all occurrences substr Instr 19

Character Functions Select substr(Guest_name, 1, 9) From Guest; -- substr(Guest_name, 1, 9) up to 9 characters Select * From Guest where instr(Guest_name, 'T', 6) > 0; Select * From Guest where instr(Guest_name, 'T', 7) > 0; 20

Assignment 7 Due Today By 5 PM 21

Assignment 8 Due Wednesday, April 8 Formatting Style Sample SQL Script File 22

Project PhaseOne: Due Monday 23