Goran Bibic

Goran Bibic

  • 454
  • 2.9k
  • 180.5k

Sum subquery MS SQL database

Jan 25 2024 8:38 AM

Need to sum this column

(t.kolicina)*(sum(s.kolicina)) as 'Kol potr repromat'

When try

sum((t.kolicina)*(sum(s.kolicina))) as 'Kol potr repromat'

Have this error

Msg 130, Level 15, State 1, Line 2
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

My code

select t.naziv as 'Naziv' ,
  (t.kolicina)*(sum(s.kolicina)) as 'Kol potr repromat'
  from dbo.normativi_roba t
  full join
normativi_lista k
ON t.id_fakture =k.id
full join
mp_racun_roba s
ON k.naziv=s.roba
where roba=(select naziv from dbo.roba_usluge where podgrupa_artikala='HRANA' and roba_usluge.naziv=s.roba)
group by t.naziv, t.jedinica_mjere, t.kolicina

 


Answers (1)