Download presentation
Presentation is loading. Please wait.
1
CS 3630 Database Design and Implementation
2
Mapping E-R Model to Relational Schema Due Wednesday, April 4, by 5 pm
Project Phase II Mapping E-R Model to Relational Schema Due Wednesday, April 4, by 5 pm
3
SQL Query Clause Select and From
From booking; select hotel_no, guest_no, room_no from booking; select Distinct hotel_no, guest_no, room_no -- Remove duplicate records -- Unique also works Should be updated using tables from Assignment 7
4
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
5
Clause Where Select * From Room Where RType = 'Single‘;
-- Where clause to specify the condition -- Operators And/Or Where Price > 35 and RType = 'Single‘; -- Where Price > 35 or RType = 'Single'
6
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‘)
7
Operator NOT (!) Select * From Room
Where Not (Price > 35 and RType = 'Family'); -- Not the same! Where Not Price > 35 and RType = 'Family'; --Where (Not Price > 35) and RType = 'Family'; --Where Price <= 35 and RType = 'Family';
8
Operator Between Select * From Room Where Price between 30 and 45;
-- inclusive Where Price Not between 30 and 45; -- Where Not Price between 30 and 45;
9
Operator IN Select * From Room Where Price in (30, 40, 45); -- Same as
-- Where Price = 30 or Price = 40 or Price = 45 Where Price Not in (30, 40, 45); -- Where Not Price in (30, 40, 45);
10
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
11
Operator Like and Char ‘_’
-- All records whose Fname has 'M' for 3rd position Select * From Guest Where guest_name like '__M%'; -- _: any single char
12
Null Value Select * From Guest Where Address = null;
-- No row is selected -- null != null Where Address is null; -- Some rows may be selected
13
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" Select Guest_no, Guest_name as GuestName Select Guest_no, Guest_name GuestName
14
Sorting the Result Select * From Room Order by Price desc;
-- ASC is the default
15
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
16
Sorting the Result Select Hotel_No, Room_No, RType From Room
Order by Hotel_No, Price desc; -- Price may not be selected
17
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" Order by "Guest Name“;
18
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
19
Character Functions Select Guest_Name || ' From ' || Address
From Guest Where Address is not null;
20
Character Functions Lower Upper Initcap length replace
-- Replace all occurrences substr Instr
21
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; where instr(Guest_name, 'T', 7) > 0;
22
Due Friday, April 6 Formatting Style
Assignment 8 Due Friday, April 6 Formatting Style
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.