SlideShare a Scribd company logo
1 of 4
describe RCDW_cHARTER_fACT;
describe RCDW_Aircraft_Dim;
Select d.AIRCRAFT_ID,
d.MANUFACTURER,
d.MODEL_NAME,
f.Hours_Flown
from RCDW_Charter_Fact f
join RCDW_Aircraft_Dim d
using (Aircraft_Key)
group by Aircraft_Id;
order by d.Aircraft_Id;
--2.1 A. Using the charter flights database, create an SQL query to return the
aircraft ID, manufacturer, model name and total hours flown (on charter flights)
for each of company's aircraft that has flown any charter flights.
Select AIRCRAFT_ID,
MANUFACTURER,
MODEL_NAME,
Sum(Hours_Flown) as "Total Hours Flown"
from RCDW_Charter_Fact
join RCDW_Aircraft_Dim
using (Aircraft_Key)
group by Aircraft_ID, MANUFACTURER,
MODEL_NAME
order by Manufacturer, Model_Name, Aircraft_Id;
--2.1 B. Modify the above query to only return total hours flown for charter
flights
during February of 2013.
Select AIRCRAFT_ID,
MANUFACTURER,
MODEL_NAME,
Sum(Hours_Flown) as "Total Hours Flown"
from RCDW_Charter_Fact
join RCDW_Aircraft_Dim
using (Aircraft_Key)
join RCDW_Date_Dim
using (Date_Key)
where Month_Num = 02
and Year = 2013
group by Aircraft_ID, MANUFACTURER,
MODEL_NAME
order by Manufacturer, Model_Name, Aircraft_Id;
--2.1 C. Modify the above query to only return total hours flown for charter
flights that took place
ON WEEKENDS during February of 2013.
Select * from RCDW_Date_Dim;
Select AIRCRAFT_ID,
MANUFACTURER,
MODEL_NAME,
Sum(Hours_Flown) as "Total Hours Flown"
from RCDW_Charter_Fact
join RCDW_Aircraft_Dim
using (Aircraft_Key)
join RCDW_Date_Dim
using (Date_Key)
where Weekend_Flag = 'Y'
and Month_Num = 02
and Year = 2013
group by Aircraft_ID, MANUFACTURER,
MODEL_NAME
order by Manufacturer, Model_Name, Aircraft_Id;
--2.2 A. Using the charter flights database, create an SQL query to return the
customer ID, first name,
last name, phone number, destination, trip date, & amount billled for each
charter flight in the company's data warehouse.
Select * from RCDW_Date_Dim;
Select Trip_Id,
Trip_Date,
Customer_ID,
First_Name,
Last_Name,
Phone_Num,
Destination,
Amount_Billed
-- Sum(Hours_Flown) as "Total Hours Flown"
from RCDW_Customer_Dim
join RCDW_Charter_Fact
using (Customer_Key)
join RCDW_Trip_Dim
using (Trip_Key)
order by Trip_Date, Trip_Id;
select * from RCDW_Charter_Fact;
--2.2 B. Modify the above query to also return the total distance flown, and
R.C. Charter's
estimated profit for the charter. (calculate estimated profit as amount billed
minus trip cost)
Select * from RCDW_Date_Dim;
Select Trip_Id,
Trip_Date,
Customer_ID,
First_Name,
Last_Name,
Phone_Num,
Destination,
Amount_Billed,
Distance,
(Amount_Billed - Trip_Cost) as "Estimated Profit"
from RCDW_Customer_Dim
join RCDW_Charter_Fact
using (Customer_Key)
join RCDW_Trip_Dim
using (Trip_Key)
order by Trip_Date, Trip_Id;
--2.2. C. Modify the above query to only return the selected columns for
charter flights
that ocurred on Mondays durng the year 2013.
Select Trip_Id,
Trip_Date,
Day_Of_Week,
Customer_ID,
First_Name,
Last_Name,
Phone_Num,
Destination,
Amount_Billed,
Distance,
(Amount_Billed - Trip_Cost) as "Estimated Profit"
from RCDW_Customer_Dim
join RCDW_Charter_Fact
using (Customer_Key)
join RCDW_Trip_Dim
using (Trip_Key)
join RCDW_Date_Dim
using (Date_Key)
where Day_Of_Week = 'Monday'
and year = 2013
order by Trip_Date, Trip_Id;
--3.1.A Write an Oracle stored function that will accept as input a pilot's
employee ID, a begin date
and an end date, and return the total number of hours that pilot as flown in the
time period repre-
sented by the dates from your data warehouse. The total should include both
hours flown as
the pilot and those flown as the copilot. Include any charter flights for which
the trip date in in the date range.
select * from RCDW_Date_Dim;
select * from RCDW_Charter_Fact;
select sum(Hours_Flown)
from RCDW_Charter_Fact ch,
RCDW_Date_Dim d,
RCDW_Pilot_Dim p
-- top half get hours flown as Pilot
where ( (p.Pilot_Key = ch.Pilot_Key
and ch.Date_Key = d.Date_Key)
and d.day between '01-Jan-13' and '01-Mar-14'
and d.Year = 2013
and p.Employee_Id = 109 )
or
-- bottom half get hours flown as Copilot
( (p.Pilot_Key = ch.CoPilot_Key
and ch.Date_Key = d.Date_Key)
and d.day between '01-Jan-13' and '01-Mar-14'
and d.Year = 2013
and p.Employee_Id = 109 );
CREATE OR REPLACE FUNCTION Sf_Hours_Flown
(p_Employee_Id IN RCDW_Pilot_Dim.Employee_Id%TYPE
,p_Begin_Day IN RCDW_Date_Dim.Day%TYPE
,p_End_Day IN RCDW_Date_Dim.Day%TYPE
)
RETURN number
IS
v_Hours_Flown RCDW_Charter_Fact.Hours_Flown%TYPE := 0;
BEGIN
select sum(Hours_Flown) INTO v_Hours_Flown
from RCDW_Charter_Fact ch,
RCDW_Date_Dim d,
RCDW_Pilot_Dim p
-- top half get hours flown as Pilot
where ( (p.Pilot_Key = ch.Pilot_Key
and ch.Date_Key = d.Date_Key)
and d.day between p_Begin_Day and p_End_Day
and p.Employee_Id = p_Employee_Id )
or
-- bottom half get hours flown as Copilot
( (p.Pilot_Key = ch.CoPilot_Key
and ch.Date_Key = d.Date_Key)
and d.day between p_Begin_Day and p_End_Day
and p.Employee_Id = p_Employee_Id );
RETURN
v_Hours_Flown;
end Sf_Hours_Flown;
/
Show errors;
--3.1.B Demonstrate that your function works by using an SQL statement such as
the following
(assumes a function named sf_hours_flown):
SELECT Sf_Hours_Flown(109,'01-Jan-13','01-Dec-13') from Dual;
--3.2.A Write an Oracle stored procedure that accepts as input an aircraft ID,
a begin date and an end
date, and returns (as an Out parmeter) the total charge for that aircraft for
the date range. The total charge
should be calculated as distance times charge per mile for any charter flights
during the date range.
select * from RCDW_AIRCRAFT_DIM;
select SUM(Amount_Billed) from RCDW_CHARTER_FACT where aircraft_Key = 1000012;
CREATE OR REPLACE PROCEDURE PRC_Total_Charge
(p_Aircraft_Id IN RCDW_Aircraft_Dim.Aircraft_Id%TYPE ,
p_Begin_Day IN RCDW_Date_Dim.Day%TYPE ,
p_End_Day IN RCDW_Date_Dim.Day%TYPE ,
p_Total_Charge OUT RCDW_Charter_Fact.Amount_Billed%TYPE
)
IS
v_Distance RCDW_Charter_Fact.Distance%TYPE :=0;
v_Charge_per_Mile RCDW_Aircraft_Dim.Charge_per_Mile%TYPE :=0;
BEGIN
select SUM(Distance), SUM(Charge_Per_Mile), SUM(Distance) * SUM(Charge_Per_Mile)
as "Total Charges"
into v_Distance , v_Charge_per_Mile , p_Total_Charge
from RCDW_CHARTER_FACT
join RCDW_Date_Dim using (Date_Key)
join RCDW_AIRCRAFT_DIM using (Aircraft_Key)
where RCDW_Date_Dim.Day between p_Begin_Day and p_End_Day
and RCDW_AIRCRAFT_DIM.Aircraft_Id = p_Aircraft_Id;
DBMS_OUTPUT.PUT_LINE('Total charges for aircraft ' || p_Aircraft_Id || ' are
$' || p_Total_Charge);
end PRC_Total_Charge;
/
Show errors;
--3.2.b
SET SERVEROUTPUT ON;
declare
g_Total_Charge number;
BEGIN
PRC_Total_Charge('2289L','01-Jan-13','31-Dec-13', :g_Total_Charge);
DBMS_OUTPUT.PUT_LINE('Total charges for aircraft ' || '2289L ' || 'are $' ||
g_Total_Charge);
END;
/

More Related Content

Viewers also liked

PaulBoosey-BeatBox-final-project-upload2
PaulBoosey-BeatBox-final-project-upload2PaulBoosey-BeatBox-final-project-upload2
PaulBoosey-BeatBox-final-project-upload2
Paul Boosey
 
консульт борисенко
консульт борисенкоконсульт борисенко
консульт борисенко
virtualtaganrog
 

Viewers also liked (10)

Rory Reference
Rory ReferenceRory Reference
Rory Reference
 
Colour palette analysis
Colour palette analysisColour palette analysis
Colour palette analysis
 
CBCF
CBCFCBCF
CBCF
 
PaulBoosey-BeatBox-final-project-upload2
PaulBoosey-BeatBox-final-project-upload2PaulBoosey-BeatBox-final-project-upload2
PaulBoosey-BeatBox-final-project-upload2
 
консульт борисенко
консульт борисенкоконсульт борисенко
консульт борисенко
 
Out Care The Competition - Presented to the Association of Fundraising Profes...
Out Care The Competition - Presented to the Association of Fundraising Profes...Out Care The Competition - Presented to the Association of Fundraising Profes...
Out Care The Competition - Presented to the Association of Fundraising Profes...
 
The Wizardry of Braintree hosted fields - PHP
The Wizardry of Braintree hosted fields - PHPThe Wizardry of Braintree hosted fields - PHP
The Wizardry of Braintree hosted fields - PHP
 
Strive to Thrive Exit Strategy
Strive to Thrive Exit StrategyStrive to Thrive Exit Strategy
Strive to Thrive Exit Strategy
 
Сильные IT-решения
Сильные IT-решенияСильные IT-решения
Сильные IT-решения
 
La thaillande ml511
La thaillande ml511La thaillande ml511
La thaillande ml511
 

Similar to RCCharter-DataWarehouseQueries

sql code for this question below Portland Airports Ltd would like a.pdf
sql code  for this question below  Portland Airports Ltd would like a.pdfsql code  for this question below  Portland Airports Ltd would like a.pdf
sql code for this question below Portland Airports Ltd would like a.pdf
dawarhosy
 
JAVA The file being read is called flightdatatxt please in.pdf
JAVA The file being read is called flightdatatxt please in.pdfJAVA The file being read is called flightdatatxt please in.pdf
JAVA The file being read is called flightdatatxt please in.pdf
adinathassociates
 
SAS writing example
SAS writing exampleSAS writing example
SAS writing example
Tianyue Wang
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
ivylinvaydak64229
 
Air Travel Analytics in SAS
Air Travel Analytics in SASAir Travel Analytics in SAS
Air Travel Analytics in SAS
Rohan Nanda
 

Similar to RCCharter-DataWarehouseQueries (20)

big data slides.pptx
big data slides.pptxbig data slides.pptx
big data slides.pptx
 
A Novel Approach To The Weight and Balance Calculation for The De Haviland Ca...
A Novel Approach To The Weight and Balance Calculation for The De Haviland Ca...A Novel Approach To The Weight and Balance Calculation for The De Haviland Ca...
A Novel Approach To The Weight and Balance Calculation for The De Haviland Ca...
 
sql code for this question below Portland Airports Ltd would like a.pdf
sql code  for this question below  Portland Airports Ltd would like a.pdfsql code  for this question below  Portland Airports Ltd would like a.pdf
sql code for this question below Portland Airports Ltd would like a.pdf
 
Airline Database Design
Airline Database DesignAirline Database Design
Airline Database Design
 
Amadeus PPT
Amadeus PPTAmadeus PPT
Amadeus PPT
 
Is Low Cost Carrier Profitable -Ryan article - Issue No. 2
Is Low Cost Carrier Profitable -Ryan article - Issue No. 2Is Low Cost Carrier Profitable -Ryan article - Issue No. 2
Is Low Cost Carrier Profitable -Ryan article - Issue No. 2
 
JAVA The file being read is called flightdatatxt please in.pdf
JAVA The file being read is called flightdatatxt please in.pdfJAVA The file being read is called flightdatatxt please in.pdf
JAVA The file being read is called flightdatatxt please in.pdf
 
Predict Price of Airline Tickets.pptx
Predict Price of Airline Tickets.pptxPredict Price of Airline Tickets.pptx
Predict Price of Airline Tickets.pptx
 
SAS writing example
SAS writing exampleSAS writing example
SAS writing example
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
 
Standoutfromthe crowds
Standoutfromthe crowdsStandoutfromthe crowds
Standoutfromthe crowds
 
FAMILIARIZATION WITH AVIONICS SUITE
FAMILIARIZATION WITH AVIONICS SUITE FAMILIARIZATION WITH AVIONICS SUITE
FAMILIARIZATION WITH AVIONICS SUITE
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
 
Revenue and Cost Saving Ideas for IAA
Revenue and Cost Saving Ideas for IAARevenue and Cost Saving Ideas for IAA
Revenue and Cost Saving Ideas for IAA
 
India Aviation ICT Forum 2013 - Manish Sinha, Deputy COO, Hyderabad Internati...
India Aviation ICT Forum 2013 - Manish Sinha, Deputy COO, Hyderabad Internati...India Aviation ICT Forum 2013 - Manish Sinha, Deputy COO, Hyderabad Internati...
India Aviation ICT Forum 2013 - Manish Sinha, Deputy COO, Hyderabad Internati...
 
masFlight March 2013 Monthly Performance Report
masFlight March 2013 Monthly Performance ReportmasFlight March 2013 Monthly Performance Report
masFlight March 2013 Monthly Performance Report
 
Course project for CEE 4674
Course project for CEE 4674Course project for CEE 4674
Course project for CEE 4674
 
Air Travel Analytics in SAS
Air Travel Analytics in SASAir Travel Analytics in SAS
Air Travel Analytics in SAS
 
Benefit/Cost Analysis For Ait Traffic Control Towers Presentation
Benefit/Cost Analysis For Ait Traffic Control Towers PresentationBenefit/Cost Analysis For Ait Traffic Control Towers Presentation
Benefit/Cost Analysis For Ait Traffic Control Towers Presentation
 
Examples of-tca-apis
Examples of-tca-apisExamples of-tca-apis
Examples of-tca-apis
 

RCCharter-DataWarehouseQueries

  • 1. describe RCDW_cHARTER_fACT; describe RCDW_Aircraft_Dim; Select d.AIRCRAFT_ID, d.MANUFACTURER, d.MODEL_NAME, f.Hours_Flown from RCDW_Charter_Fact f join RCDW_Aircraft_Dim d using (Aircraft_Key) group by Aircraft_Id; order by d.Aircraft_Id; --2.1 A. Using the charter flights database, create an SQL query to return the aircraft ID, manufacturer, model name and total hours flown (on charter flights) for each of company's aircraft that has flown any charter flights. Select AIRCRAFT_ID, MANUFACTURER, MODEL_NAME, Sum(Hours_Flown) as "Total Hours Flown" from RCDW_Charter_Fact join RCDW_Aircraft_Dim using (Aircraft_Key) group by Aircraft_ID, MANUFACTURER, MODEL_NAME order by Manufacturer, Model_Name, Aircraft_Id; --2.1 B. Modify the above query to only return total hours flown for charter flights during February of 2013. Select AIRCRAFT_ID, MANUFACTURER, MODEL_NAME, Sum(Hours_Flown) as "Total Hours Flown" from RCDW_Charter_Fact join RCDW_Aircraft_Dim using (Aircraft_Key) join RCDW_Date_Dim using (Date_Key) where Month_Num = 02 and Year = 2013 group by Aircraft_ID, MANUFACTURER, MODEL_NAME order by Manufacturer, Model_Name, Aircraft_Id; --2.1 C. Modify the above query to only return total hours flown for charter flights that took place ON WEEKENDS during February of 2013. Select * from RCDW_Date_Dim; Select AIRCRAFT_ID, MANUFACTURER, MODEL_NAME, Sum(Hours_Flown) as "Total Hours Flown" from RCDW_Charter_Fact join RCDW_Aircraft_Dim using (Aircraft_Key) join RCDW_Date_Dim using (Date_Key) where Weekend_Flag = 'Y' and Month_Num = 02 and Year = 2013 group by Aircraft_ID, MANUFACTURER, MODEL_NAME
  • 2. order by Manufacturer, Model_Name, Aircraft_Id; --2.2 A. Using the charter flights database, create an SQL query to return the customer ID, first name, last name, phone number, destination, trip date, & amount billled for each charter flight in the company's data warehouse. Select * from RCDW_Date_Dim; Select Trip_Id, Trip_Date, Customer_ID, First_Name, Last_Name, Phone_Num, Destination, Amount_Billed -- Sum(Hours_Flown) as "Total Hours Flown" from RCDW_Customer_Dim join RCDW_Charter_Fact using (Customer_Key) join RCDW_Trip_Dim using (Trip_Key) order by Trip_Date, Trip_Id; select * from RCDW_Charter_Fact; --2.2 B. Modify the above query to also return the total distance flown, and R.C. Charter's estimated profit for the charter. (calculate estimated profit as amount billed minus trip cost) Select * from RCDW_Date_Dim; Select Trip_Id, Trip_Date, Customer_ID, First_Name, Last_Name, Phone_Num, Destination, Amount_Billed, Distance, (Amount_Billed - Trip_Cost) as "Estimated Profit" from RCDW_Customer_Dim join RCDW_Charter_Fact using (Customer_Key) join RCDW_Trip_Dim using (Trip_Key) order by Trip_Date, Trip_Id; --2.2. C. Modify the above query to only return the selected columns for charter flights that ocurred on Mondays durng the year 2013. Select Trip_Id, Trip_Date, Day_Of_Week, Customer_ID, First_Name, Last_Name, Phone_Num, Destination, Amount_Billed, Distance, (Amount_Billed - Trip_Cost) as "Estimated Profit" from RCDW_Customer_Dim join RCDW_Charter_Fact using (Customer_Key) join RCDW_Trip_Dim
  • 3. using (Trip_Key) join RCDW_Date_Dim using (Date_Key) where Day_Of_Week = 'Monday' and year = 2013 order by Trip_Date, Trip_Id; --3.1.A Write an Oracle stored function that will accept as input a pilot's employee ID, a begin date and an end date, and return the total number of hours that pilot as flown in the time period repre- sented by the dates from your data warehouse. The total should include both hours flown as the pilot and those flown as the copilot. Include any charter flights for which the trip date in in the date range. select * from RCDW_Date_Dim; select * from RCDW_Charter_Fact; select sum(Hours_Flown) from RCDW_Charter_Fact ch, RCDW_Date_Dim d, RCDW_Pilot_Dim p -- top half get hours flown as Pilot where ( (p.Pilot_Key = ch.Pilot_Key and ch.Date_Key = d.Date_Key) and d.day between '01-Jan-13' and '01-Mar-14' and d.Year = 2013 and p.Employee_Id = 109 ) or -- bottom half get hours flown as Copilot ( (p.Pilot_Key = ch.CoPilot_Key and ch.Date_Key = d.Date_Key) and d.day between '01-Jan-13' and '01-Mar-14' and d.Year = 2013 and p.Employee_Id = 109 ); CREATE OR REPLACE FUNCTION Sf_Hours_Flown (p_Employee_Id IN RCDW_Pilot_Dim.Employee_Id%TYPE ,p_Begin_Day IN RCDW_Date_Dim.Day%TYPE ,p_End_Day IN RCDW_Date_Dim.Day%TYPE ) RETURN number IS v_Hours_Flown RCDW_Charter_Fact.Hours_Flown%TYPE := 0; BEGIN select sum(Hours_Flown) INTO v_Hours_Flown from RCDW_Charter_Fact ch, RCDW_Date_Dim d, RCDW_Pilot_Dim p -- top half get hours flown as Pilot where ( (p.Pilot_Key = ch.Pilot_Key and ch.Date_Key = d.Date_Key) and d.day between p_Begin_Day and p_End_Day and p.Employee_Id = p_Employee_Id ) or -- bottom half get hours flown as Copilot ( (p.Pilot_Key = ch.CoPilot_Key and ch.Date_Key = d.Date_Key) and d.day between p_Begin_Day and p_End_Day and p.Employee_Id = p_Employee_Id ); RETURN v_Hours_Flown;
  • 4. end Sf_Hours_Flown; / Show errors; --3.1.B Demonstrate that your function works by using an SQL statement such as the following (assumes a function named sf_hours_flown): SELECT Sf_Hours_Flown(109,'01-Jan-13','01-Dec-13') from Dual; --3.2.A Write an Oracle stored procedure that accepts as input an aircraft ID, a begin date and an end date, and returns (as an Out parmeter) the total charge for that aircraft for the date range. The total charge should be calculated as distance times charge per mile for any charter flights during the date range. select * from RCDW_AIRCRAFT_DIM; select SUM(Amount_Billed) from RCDW_CHARTER_FACT where aircraft_Key = 1000012; CREATE OR REPLACE PROCEDURE PRC_Total_Charge (p_Aircraft_Id IN RCDW_Aircraft_Dim.Aircraft_Id%TYPE , p_Begin_Day IN RCDW_Date_Dim.Day%TYPE , p_End_Day IN RCDW_Date_Dim.Day%TYPE , p_Total_Charge OUT RCDW_Charter_Fact.Amount_Billed%TYPE ) IS v_Distance RCDW_Charter_Fact.Distance%TYPE :=0; v_Charge_per_Mile RCDW_Aircraft_Dim.Charge_per_Mile%TYPE :=0; BEGIN select SUM(Distance), SUM(Charge_Per_Mile), SUM(Distance) * SUM(Charge_Per_Mile) as "Total Charges" into v_Distance , v_Charge_per_Mile , p_Total_Charge from RCDW_CHARTER_FACT join RCDW_Date_Dim using (Date_Key) join RCDW_AIRCRAFT_DIM using (Aircraft_Key) where RCDW_Date_Dim.Day between p_Begin_Day and p_End_Day and RCDW_AIRCRAFT_DIM.Aircraft_Id = p_Aircraft_Id; DBMS_OUTPUT.PUT_LINE('Total charges for aircraft ' || p_Aircraft_Id || ' are $' || p_Total_Charge); end PRC_Total_Charge; / Show errors; --3.2.b SET SERVEROUTPUT ON; declare g_Total_Charge number; BEGIN PRC_Total_Charge('2289L','01-Jan-13','31-Dec-13', :g_Total_Charge); DBMS_OUTPUT.PUT_LINE('Total charges for aircraft ' || '2289L ' || 'are $' || g_Total_Charge); END; /