RSS Forums RSS
Please support our Oracle advertiser: Programming Forums
Views: 1449 | Replies: 3
Reply
Join Date: Apr 2007
Location: Birmingham
Posts: 379
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Help complicated

  #1  
Apr 27th, 2007
hello, ive been busy trying over and over and over again to write a block of SQL that will perform this task for me but have failed ever time. hopefully someone can point me in the right direction or at least gime a hand cheers.

task : to work out what is the average cost of hire contracts for each of the five branches?

i have 5 tables set up

which are as follows

/* creates the Branch table
    primary key 'BranchNo' */
CREATE TABLE Branch (
BranchNo NUMBER(3) CONSTRAINT pk_branch PRIMARY KEY ,
BranchName VARCHAR2(28) ,
BranchAddress VARCHAR2(40) ,
City VARCHAR2(18) ,
B_tel_no VARCHAR2(12) );
 
/* creates the staff table
    primary key 'StaffID'
    foreign key 'BranchNo' */
 
CREATE TABLE Staff (
StaffID NUMBER(3) CONSTRAINT pk_staff PRIMARY KEY ,
StaffName VARCHAR2(20) ,
BranchNo NUMBER(3) CONSTRAINT fk_BranchNo references Branch(BranchNo) ,
JobTitle VARCHAR2(20) );
 
/* creates the Customer table
    primary key 'CustomerNo' */
 
CREATE TABLE Customer (
CustomerNo NUMBER(3) CONSTRAINT pk_customer PRIMARY KEY ,
CustomerName VARCHAR2(20) ,
CustomerAddress VARCHAR2(48) ,
CustomerTelNo VARCHAR2(12) );
 
/* creates the Car table
    primary key 'CarRegNo' */
 
CREATE TABLE Car (
CarRegNo NUMBER(3) CONSTRAINT pk_car PRIMARY KEY ,
CarTypeNo VARCHAR2(28) ,
CarModel VARCHAR2(48) ,
Colour VARCHAR2(18) ,
Mileage NUMBER(7) );
 
/* creates the Type table
    primary key 'CarTypeNo' */
 
CREATE TABLE Type (
CarTypeNo NUMBER(3) CONSTRAINT pk_type PRIMARY KEY ,
TypeDescription VARCHAR2(48) ,
DailyCharge NUMBER(5,2) );
 
/* creates the HireContract table
    primary key 'Hire_Contract_No' & 'CarRegNo'
    foreign key 'CarRegNo' & 'CustomerNo' */
 
CREATE TABLE HireContract (
Hire_Contract_No NUMBER(3) ,
CarRegNo NUMBER(3) CONSTRAINT fk_CarRegNo references Car(CarRegNo),
CustomerNo NUMBER(3) CONSTRAINT fk_CustomerNo references Customer(CustomerNo),
StaffID NUMBER(3) ,
CarTypeNo VARCHAR2(3) ,
IssueDate DATE ,
DueReturnDate DATE ,
ActualReturnDate DATE ,
CarCost NUMBER(6,2) ,
CONSTRAINT pk_Hire PRIMARY KEY(Hire_Contract_No, CarRegNo) ,
CONSTRAINT ch_ActualReturnDate CHECK (ActualReturnDate > IssueDate) ,
CONSTRAINT ch_DueReturnDate CHECK (DueReturnDate > IssueDate) );

and as the question states i need to work out the average cost of hire contracts for each branch. The tables have been set up this way on purpose but i just cannot seem to find a way to achieve this goal ? any ideas.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: London
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: complicated

  #2  
Apr 27th, 2007
Without answering your whole question I'll give you a start

You need 3 of the tables to find cost per hire -
HireContract
Staff
Branch

Join them to each other and you should then be able to find the contracts for each branch (join fields are StaffID and BranchNo)

Give it a go and post here when your done

Cheers

D
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 379
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Solution Re: complicated

  #3  
Apr 27th, 2007
Originally Posted by davidcairns View Post
Without answering your whole question I'll give you a start

You need 3 of the tables to find cost per hire -
HireContract
Staff
Branch

Join them to each other and you should then be able to find the contracts for each branch (join fields are StaffID and BranchNo)

Give it a go and post here when your done

Cheers

D


hello, cheers for the reply i actually managed to figure it out myself after a long and painful process. Really am greatful for the help though. Thanks ..
Reply With Quote  
Join Date: Feb 2007
Location: London
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: complicated

  #4  
Apr 28th, 2007
Glad to hear that, you always get more out of it if you manage it yourself
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:09 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC