Code (sql):
WITH Grupa1 AS (
SELECT
t2.Referent,
FORMAT(SUM ((t1.Kolicina*t1.cena)-(t1.kolicina*t1.cena)*t1.rabat/100), 'N') AS VrednostPonuda
FROM ponudaSta t1
LEFT JOIN PonudaZag t2 ON t2.RbrPonude = t1.RbrPonude
WHERE t2.Datum >='2022-1-1'
GROUP BY ROLLUP (t2.Referent)
),
Grupa2 AS (
SELECT Referent, COUNT(RbrPonude) AS BrojSvihPonuda
FROM PonudaZag
WHERE Datum >='2022-01-01'
GROUP BY Referent
)
SELECT Grupa1.Referent, Grupa1.VrednostPonuda, Grupa2.BrojSvihPonuda
FROM Grupa2
JOIN Grupa1 ON Grupa1.Referent =Grupa2.Referent
WITH Grupa1 AS (
SELECT
t2.Referent,
FORMAT(SUM ((t1.Kolicina*t1.cena)-(t1.kolicina*t1.cena)*t1.rabat/100), 'N') AS VrednostPonuda
FROM ponudaSta t1
LEFT JOIN PonudaZag t2 ON t2.RbrPonude = t1.RbrPonude
WHERE t2.Datum >='2022-1-1'
GROUP BY ROLLUP (t2.Referent)
),
Grupa2 AS (
SELECT Referent, COUNT(RbrPonude) AS BrojSvihPonuda
FROM PonudaZag
WHERE Datum >='2022-01-01'
GROUP BY Referent
)
SELECT Grupa1.Referent, Grupa1.VrednostPonuda, Grupa2.BrojSvihPonuda
FROM Grupa2
JOIN Grupa1 ON Grupa1.Referent =Grupa2.Referent