USE AdventureWorksOBP
GO

SELECT k.Tip, SUM(s.UkupnaCijena)
FROM KreditnaKartica AS k
INNER JOIN Racun AS r ON r.KreditnaKarticaID = k.IDKreditnaKartica
INNER JOIN Stavka as s ON s.RacunID = r.IDRacun
INNER JOIN Proizvod as p on s.ProizvodID = p.IDProizvod
WHERE p.Boja = 'Crna'
GROUP BY k.Tip
HAVING SUM(s.UkupnaCijena) > 9000000