Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mind teaser SQL

I have been trying to answer the questions found on http://www.sql-ex.ru/learn_exercises.php#answer_ref recently since I am a newbie in sql, as you can see from my previous posts regarding sql. I across this question:

Exercise: 23 Find the makers producing at least both a pc having speed not less than 750 MHz and a laptop having speed not less than 750 MHz. Result set: Maker

The following is my answer which is incorrect since it uses or. can anyone guide me to a good direction by either giving me a link where to search or what join should I use.

  SELECT pt.maker    
    FROM product pt, 
         laptop l, 
         pc    
   WHERE (pt.model = pc.model 
     AND pc.speed >=750) 
      OR (pt.model = l.model 
     AND l.speed >=750)
GROUP BY pt.maker
like image 822
IanCian Avatar asked Dec 27 '25 16:12

IanCian


1 Answers

Close, if the tables and column definitions are right (I don't have a login for that site), it should be something like:

SELECT distinct pt_pc.maker
FROM  
  laptop l 
    inner join product pt_l on pt_l.model=l.model, 
  pc
    inner join product pt_pc on pt_pc.model=pc.model
WHERE pc.speed >=750 and l.speed >=750 and pt_l.maker=pt_pc.maker

so basically you want one pc with speed >=750 and one laptop with speed >=750 made by the same guy.

like image 64
Blindy Avatar answered Dec 30 '25 07:12

Blindy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!