HI , i have a little problemn. I have to tables codMP and Content.Display like this.
codMP name In
1 x ? - 20 - here i want to sum the column from the second table where
codMP = with what is in the column codMP. The same for the
2 Y ? – 102 other rows.
3 Z ? - 25
Tabela Materii Prime


IDF codMP Q
1 1 10
2 1 10

1 2 30
1 3 25
2 2 82


Please help.

Recommended Answers

All 2 Replies

try this:

SELECT codMP, SUM(Cantitate) AS 'SUM' FROM dbo.continut GROUP BY codMP

output:

1 | 20
2 | 112
3 | 25


or

SELECT  *
FROM    dbo.Materii
        JOIN ( SELECT   codMP
                      , SUM(Cantitate) AS 'SUM'
               FROM     dbo.continut
               GROUP BY codMP
             ) AS a ON dbo.Materii.codMp = a.codMP

output:

1	x	?-20	1	20
2	y	?-102	2	112
3	z	?-25	3	25

Thank you verry much , it realy helped me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.