Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197k

Group from Join or Union Two Query

Jul 26 2023 9:20 AM

Need  to sum  'Kol prod danas' column and group by 'Prodano danas' column

 SELECT
    c.sifra AS 'Šifra RM',
    c.naziv AS 'Naziv RM',
    SUM(c.kolicina) AS 'Kol RM',
   -- d.sifra AS success1,
    d.roba AS 'Prodano danas'	,
    SUM(d.kolicina) AS 'Kol prod danas'
FROM
    popis_repromaterijal_roba AS c 
    JOIN mp_racun_roba AS d  
	
	ON D.id=C.id
	GROUP BY
    c.sifra,
    c.naziv,
    d.roba
	

My result

Šifra RM	Naziv RM	Kol RM	Prodano danas	Kol prod danas
1	MESO MLJEVENO	4.1060	HLJEB BIJELI POSAVAC 	1.0000
2	PICA SUNKA	6.2060	HLJEB BIJELI POSAVAC 	1.0000
3	PILETINA	4.1220	HLJEB BIJELI POSAVAC 	2.0000
4	SIR GAUDA	2.9680	PIZZA 	1.0000
5	KROMPIR	5.0000	BUREK VRHNJE 	1.0000
6	SIR SVJEZI	5.0000	HLJEB BIJELI POSAVAC 	-2.0000
7	BRASNO	200.0000	PIZZA 	-1.0000

MY result need to be

Šifra RM	Naziv RM	Kol RM	Prodano danas	Kol prod danas
1	MESO MLJEVENO	4.1060	HLJEB BIJELI POSAVAC 	2.0000
2	PICA SUNKA	6.2060	    BUREK VRHNJE 	1.0000
3	PILETINA	4.1220	    
4	SIR GAUDA	2.9680	    
5	KROMPIR	5.0000	
6	SIR SVJEZI	5.0000	
7	BRASNO	200.0000	

 


Answers (6)