If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > need help with queries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-14-04, 15:43
skouliki skouliki is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
need help with queries

Ok, following tables exist:

MECHANIC: mech_id, name, competence_level
CAR: car_ref# , make, model, owner_name, value_cat, car_reg#
JOB: job_name, difficulty_level, labour_cost
BOOKING: car_ref#, mech_id, job_name, date


Ok, i have problems creating the sql for the following example queries:

List make, model of all cars that have difficulty_level 4 or above performed since 1/1/2004.

List car_reg# and make of any car that was worked on by all mechanics


Can somebody please let me know how to do this with SQL or maybe even in relational algebra??

I am having a mental blockage and any help would be highly appreciated.

Thx
Reply With Quote
  #2 (permalink)  
Old 01-14-04, 17:15
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
List make, model of all cars that have difficulty_level 4 or above performed since 1/1/2004.
Can't, there is no relationship between the relevant tables.

List car_reg# and make of any car that was worked on by all mechanics
Again, not all the relationships exist between tables.
__________________
visit: relationary

Last edited by certus; 01-14-04 at 17:17.
Reply With Quote
  #3 (permalink)  
Old 01-15-04, 07:53
skouliki skouliki is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
well, that would explain things.. is there really no way?? doesn't the booking table give the relationships??
Reply With Quote
  #4 (permalink)  
Old 01-15-04, 10:57
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
You may have to modify the query depending on the relationships.

select c.*
from car c
INNER JOIN
(select car_ref
from bookings b
INNER JOIN
job j ON
b.job_name = j.job_name AND
(b.date > 1/1/2004 OR j.difficulty_level > 4)) v1 ON
c.car_ref = v1.car_ref;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #5 (permalink)  
Old 01-15-04, 12:59
skouliki skouliki is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
first of all thanks for the quick answers!

would somebody mind explaining this in detail?? how did Certus come to a different opinion??

thx
Reply With Quote
  #6 (permalink)  
Old 01-15-04, 13:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what is this, homework?

we don't answer homework questions on this forum

but the model is trivial, certus, BOOKING is a three-way intersection

the queries are piece of cake

List make, model of all cars that have [had a job of] difficulty_level 4 or above performed since 1/1/2004. --
Code:
select C.make
     , C.model
  from CAR C
inner
  join BOOKING B
    on C.car_ref# = B.car_ref#
inner
  join JOB J
    on B.job_name = J.job_name
 where B.date > '2004-01-01'
   and J.difficulty_level >= 4
List car_reg# and make of any car that was worked on by all mechanics --
Code:
select C.car_reg#
     , C.make
  from CAR C
inner
  join BOOKING B
    on C.car_ref# = B.car_ref#
inner
  join MECHANIC M
    on B.mech_id = M.mech_id
group
    by C.car_reg#
     , C.make
having count(distinct M.mech_id)
     = ( select count(*)
           from MECHANIC )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-15-04, 13:53
skouliki skouliki is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
cheers for the answer.. homework in the sence of school?? not exactly, i am just trying to improve my skills with some self study.. so i am just doing this for myself...

guess thread can be closed..
Reply With Quote
  #8 (permalink)  
Old 01-15-04, 14:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
good thing it's not homework, because there are a couple fatal flaws in there that i didn't tell you about, that will surely knock you down from an A to a B- or C

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 01-15-04, 14:37
skouliki skouliki is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Talking

if its just a couple of flaws im sure my teacher (guess thats me) won't mind....
Reply With Quote
  #10 (permalink)  
Old 01-15-04, 17:53
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
They're not flaws. They're features. Just ask Microsoft.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #11 (permalink)  
Old 01-16-04, 20:33
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
I was tired when I read that question...really!
__________________
visit: relationary
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On