Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --zad2
- 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)
- where id_gatunku is not null and (extract(year from czas), id_gatunku, dlugosc) in
- (select extract(YEAR FROM czas) rok, id_gatunku, max(dlugosc) from rejestry
- where id_gatunku is not null
- group by czas, id_gatunku);
- --zad3
- select*
- from rejestry
- where extract(month from czas) = 5 and extract(day from czas) in (6,7)
- and waga =(
- select max(waga)
- from rejestry
- where extract(month from czas) = 5
- and extract(day from czas) in (6,7)
- );
- --zad6/7
- SELECT id_kierowcy,
- nazwisko,
- imie,
- adres,
- COUNT(nr_rejestr),
- (SELECT COUNT(nr_rejestr)
- FROM pojazdy
- WHERE typ LIKE 'samochod osobowy'
- AND wlasciciel = 362729
- ),
- (SELECT COUNT(nr_rejestr)
- FROM pojazdy
- WHERE typ LIKE 'motocykl'
- AND wlasciciel = 362729
- )
- FROM kierowcy
- JOIN pojazdy
- ON (wlasciciel = id_kierowcy)
- WHERE typ IN ('samochod osobowy', 'motocykl')
- GROUP BY id_kierowcy,
- nazwisko,
- imie,
- adres
- HAVING COUNT(nr_rejestr) =
- (SELECT MAX(COUNT(nr_rejestr))
- FROM pojazdy
- WHERE typ IN('samochod osobowy', 'motocykl')
- GROUP BY wlasciciel
- );
- --Zad11
- select * from (
- select typ, max(liczebnosc) as maxliczba
- from
- (
- select typ, marka, modell, count(*) liczebnosc
- from pojazdy
- group by typ, marka, modell
- )
- group by typ) t1 join (select typ, marka, modell, count(*) as liczebnosc
- from pojazdy
- group by typ, marka, modell) t2 on(t1.typ = t2.typ and t1.maxliczba = t2.liczebnosc);
- --zad 15
- select tryb, stopien, kierunek, rok, count(*) from studenci group by rollup(tryb, stopien, kierunek, rok);
- --zad 18
- SELECT decode(groping(lowiska.nazwa),1,'wszystkie lowiska',lowiska.nazwa) "Lowiska",
- decode(groping(gatunki.nazwa),1,'razem',gatunki.nazwa) "Gatunki"
- gatunki.nazwa "Gatunki",
- COUNT(*),
- SUM(waga),
- COUNT(DISTINCT id_wedkarza)
- FROM rejestry
- JOIN lowiska USING(id_lowiska)
- JOIN gatunki USING(id_gatunku)
- GROUP BY grouping sets((lowiska.nazwa, gatunki.nazwa),(lowiska.nazwa), (gatunki.nazwa),());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement