0
$\begingroup$

Using the following relations:

consultant(id,Name,Skill) 

CustomerCompany(Id,name Address, Phone, Email, WebAddr,Market)

project(id,StartDate,EndDate,ConsultantID,CustomerId,Days)

Invoice(id,Date,Customer,Amount,Status)

Im trying to work out the following scenario using SQL and Relational algebra

Find the names of the consultants and the names of customers, where the consultant has worked for the customer, and the customer received an invoice in the range of GBP 100k to 200k

Using SQL i have:

Select I.amount, C.name 
from CustomerCompany C, Invoice I 
where I.Customer= C.id and > all
( 
  select C.name, Con.Name 
  from CustomerCompany, Con Consultant 
  where i.amount between 100 and 200
 );

Relational algebra:

amount = σ(Invoice, amount>=100 and amount<=200)

joininv= Ⓧ(amount, Customer, CustomerCompany, id)

joincon Ⓧ(joiniv, Consultant id, Project, ConsultantID)

π =(joincon, name, Name)

I was wondering if write or wrong?

Thanks for any help!

$\endgroup$
2
$\begingroup$

The correct SQL would be :

select co.name, cu.name
from consultant co join project pr on co.id = pr.ConsultantID
                   join CustomerCompany cu on cu.id = pr.CustomerId
                   join Invoice i on i.Customer = pr.CustomerId
where i.amount between 100 and 200

Converting to relation algebra is straightforward...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.