Advertisement
KeeJayBe

SQL oefeningen join

Nov 28th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.80 KB | None | 0 0
  1. /* 30 */
  2. select naam, soort, hoogte from planten p, soorten s where p.soortid=s.soortid and soort = 'water' order by hoogte
  3.  
  4. /* 31 wel zonder kleuren want da lukt mij nie */
  5. select naam, soort, kleur, hoogte, bl_b
  6. from planten p, soorten s, kleuren k
  7. where p.soortid=s.soortid and p.kleurid=k.kleurid and bl_b < 8 and hoogte between 100 and 200 and soort not in ('boom', 'heester') and kleur in ('rood', 'blauw')
  8. order by soort, naam
  9.  
  10. /* 32 */
  11. select soort, min(prijs) from soorten s, planten p where p.soortid=s.soortid and bl_b between 5 and 6 group by soort order by soort
  12.  
  13. /* 33 */
  14. select distinct(soort), kleur from soorten s, planten p, kleuren k where p.kleurid=k.kleurid and p.soortid=s.soortid and kleur = 'rood'
  15.  
  16. /* 34 */
  17. select soort, kleur, count(*) from planten p, soorten s, kleuren k where p.kleurid=k.kleurid and p.soortid= s.soortid group by soort, kleur
  18.  
  19. /* 35 */
  20. select naam, count(o.artcode) from leveranciers l, offertes o where l.levcode=o.levcode and levertermijn <= 18 group by 1 order by 1
  21.  
  22. /* 36 */
  23. select DATE_FORMAT(leverdatum, "%d/%m/%Y") as "leverdatum", bl.bestelnr, naam, sum(aantal) as "totaal aantal", sum(bl.aantal * bl.prijs) as "bedrag" from bestellingen b, leveranciers l, bestellijnen bl where bl.bestelnr=b.bestelnr and b.levcode=l.levcode group by 1, bl.bestelnr order by bl.bestelnr
  24.  
  25. /* 37 */
  26. select distinct woonplaats from leveranciers l, soorten s, planten p, offertes o where o.levcode=l.levcode and o.artcode=p.artcode and p.soortid=s.soortid and soort= 'vast'
  27.  
  28. /* 38 */
  29. select p.artcode, naam, min(offerteprijs), max(offerteprijs) from planten p, offertes o where p.artcode=o.artcode group by naam order by naam
  30.  
  31. /* 39 */
  32. select bestelnr, date_format(leverdatum, '%d/%m/%Y'), besteldatum, bedrag, case when besteldatum > '2003-03-05' then 'te laat' else '' end as opmerking from bestellingen
  33.  
  34. /* 40 */
  35. select l.naam, count(distinct(soortID)) as aantal from leveranciers l, offertes o, planten p where l.levcode=o.levcode and o.artcode=p.artcode group by naam order by aantal desc
  36.  
  37. /* 41 */
  38. select l.naam, soort from leveranciers l, offertes o, planten p, soorten s where l.levcode=o.levcode and o.artcode=p.artcode and p.soortid=s.soortid group by naam, soort
  39.  
  40. /* 42 fout */
  41. select p.naam, p.bl_b, pp.naam, pp.bl_b from planten p, planten pp, soorten s, soorten ss where p.soortid=s.soortid and pp.soortid=ss.soortid and s.soort='vast' and ss.soort='vast' and p.bl_b<pp.bl_b group by pp.naam order by p.bl_b
  42.  
  43. /* 43 niet helemaal correct volgens resultset */
  44. select b.bestelnr, b.artcodelev, prijs - offerteprijs as verschil from offertes o, bestellijnen b, bestellingen bb where b.bestelnr=bb.bestelnr and bb.levcode=o.levcode group by bestelnr
  45.  
  46. /* 44 */
  47. select bestelnr, b.levcode, l.naam, besteldatum from leveranciers l left join bestellingen b on b.levcode=l.levcode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement