Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. --zad2
  2. select gatunki.nazwa, lowiska.nazwa, wedkarze.nazwisko, rejestry.dlugosc from rejestry join wedkarze using(id_wedkarza) join gatunki using(id_gatunku) join lowiska using(id_lowiska)
  3. where id_gatunku is not null and (extract(year from czas), id_gatunku, dlugosc) in
  4. (select extract(YEAR FROM czas) rok, id_gatunku, max(dlugosc) from rejestry
  5. where id_gatunku is not null
  6. group by czas, id_gatunku);
  7.  
  8. --zad3
  9. select*
  10. from rejestry
  11. where extract(month from czas) = 5 and extract(day from czas) in (6,7)
  12. and waga =(
  13. select max(waga)
  14. from rejestry
  15. where extract(month from czas) = 5
  16. and extract(day from czas) in (6,7)
  17. );
  18.  
  19. --zad6/7
  20. SELECT id_kierowcy,
  21. nazwisko,
  22. imie,
  23. adres,
  24. COUNT(nr_rejestr),
  25. (SELECT COUNT(nr_rejestr)
  26. FROM pojazdy
  27. WHERE typ LIKE 'samochod osobowy'
  28. AND wlasciciel = 362729
  29. ),
  30. (SELECT COUNT(nr_rejestr)
  31. FROM pojazdy
  32. WHERE typ LIKE 'motocykl'
  33. AND wlasciciel = 362729
  34. )
  35. FROM kierowcy
  36. JOIN pojazdy
  37. ON (wlasciciel = id_kierowcy)
  38. WHERE typ IN ('samochod osobowy', 'motocykl')
  39. GROUP BY id_kierowcy,
  40. nazwisko,
  41. imie,
  42. adres
  43. HAVING COUNT(nr_rejestr) =
  44. (SELECT MAX(COUNT(nr_rejestr))
  45. FROM pojazdy
  46. WHERE typ IN('samochod osobowy', 'motocykl')
  47. GROUP BY wlasciciel
  48. );
  49.  
  50. --Zad11
  51. select * from (
  52. select typ, max(liczebnosc) as maxliczba
  53. from
  54. (
  55. select typ, marka, modell, count(*) liczebnosc
  56. from pojazdy
  57. group by typ, marka, modell
  58. )
  59. group by typ) t1 join (select typ, marka, modell, count(*) as liczebnosc
  60. from pojazdy
  61. group by typ, marka, modell) t2 on(t1.typ = t2.typ and t1.maxliczba = t2.liczebnosc);
  62.  
  63. --zad 15
  64. select tryb, stopien, kierunek, rok, count(*) from studenci group by rollup(tryb, stopien, kierunek, rok);
  65.  
  66. --zad 18
  67. SELECT decode(groping(lowiska.nazwa),1,'wszystkie lowiska',lowiska.nazwa) "Lowiska",
  68. decode(groping(gatunki.nazwa),1,'razem',gatunki.nazwa) "Gatunki"
  69. gatunki.nazwa "Gatunki",
  70. COUNT(*),
  71. SUM(waga),
  72. COUNT(DISTINCT id_wedkarza)
  73. FROM rejestry
  74. JOIN lowiska USING(id_lowiska)
  75. JOIN gatunki USING(id_gatunku)
  76. GROUP BY grouping sets((lowiska.nazwa, gatunki.nazwa),(lowiska.nazwa), (gatunki.nazwa),());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement