cs 3630 database design and implementation. sql query clause select and from select * from booking;...
TRANSCRIPT
![Page 1: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/1.jpg)
CS 3630 Database Design and Implementation
![Page 2: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/2.jpg)
SQL QueryClause 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
![Page 3: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/3.jpg)
Oracle Command Column (Col)Column Hotel_no format A9
Col Hotel_No format a9 heading 'Hotel No'
-- This also workcol Hotel_no format a9 heading "Hotel No"
-- to get leading decimal digitsColumn Price format $999.99 heading 'Price/Night'
-- to get leading 0sColumn Price format $099.99 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
![Page 4: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/4.jpg)
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
![Page 5: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/5.jpg)
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
![Page 6: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/6.jpg)
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
![Page 7: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/7.jpg)
Operator Between
Select *From RoomWhere Price between 30 and 45;
-- Operator Between-- inclusive
Select *From RoomWhere Price Not between 30 and 45;-- Where Not Price between 30 and 45;
7
![Page 8: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/8.jpg)
Operator IN
Select *From RoomWhere Price in (30, 40, 45);-- Same as-- Where Price = 30 or Price = 40 or Price = 45
Select *From RoomWhere Price Not in (30, 40, 45);-- Same as-- Where Not Price in (30, 40, 45);
8
![Page 9: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/9.jpg)
Comparing StringsOperator Like and %
Select *From guestWhere guest_name = 'Mary Tregear'Where guest_name like 'M%';-- All guests with name beginning with 'M‘-- %: any string of zero or more chars
9
![Page 10: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/10.jpg)
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
![Page 11: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/11.jpg)
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
![Page 12: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/12.jpg)
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
![Page 13: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/13.jpg)
Sorting the Result
Select *
From Room
Order by Price desc;
-- ASC is the default
13
![Page 14: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/14.jpg)
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
![Page 15: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/15.jpg)
Sorting the Result
Select Hotel_No, Room_No, RType
From Room
Order by Hotel_No, Price desc;
-- Price may not be selected
15
![Page 16: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/16.jpg)
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
![Page 17: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/17.jpg)
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
![Page 18: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/18.jpg)
Character Functions
Select Guest_Name || ' From ' || Address
From Guest
Where Address is not null;
18
![Page 19: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/19.jpg)
Character Functions
Lower
Upper
Initcap
length
replace
-- Replace all occurrences
substr
Instr
19
![Page 20: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/20.jpg)
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
![Page 21: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/21.jpg)
Assignment 7
Due Today By 5 PM
21
![Page 22: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/22.jpg)
Assignment 8
Due Wednesday, April 8
Formatting
Style
Sample SQL Script File
22
![Page 23: 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](https://reader035.vdocument.in/reader035/viewer/2022062221/56649cfa5503460f949cbb9c/html5/thumbnails/23.jpg)
Project
PhaseOne: Due Monday
23