USE AdventureWorksOBP

--ROLLUP

SELECT k.Prezime, k.Ime, COUNT(*) as IzdaniRacuni FROM Racun as r
INNER JOIN Kupac as k on r.KupacID = k.IDKupac
WHERE k.Prezime IN ('Adams', 'Simmons')
GROUP BY ROLLUP (k.Prezime, k.Ime)
ORDER BY IzdaniRacuni

-- CUBE

SELECT kom.Ime, kom.Prezime, COUNT(*) as IzdaniRacuni FROM Racun as r
INNER JOIN Komercijalist as kom ON r.KomercijalistID = kom.IDKomercijalist
WHERE kom.Prezime LIKE 'A%'
GROUP BY CUBE(kom.Ime, kom.Prezime)


--GROUPING SETS
SELECT p.Boja, SUM(s.UkupnaCijena) FROM Stavka as s
INNER JOIN Proizvod as p ON s.ProizvodID = p.IDProizvod
WHERE p.Boja IS NOT NULL
GROUP BY GROUPING SETS ((p.Boja), ())
