My tables look like this:
tblartikel(artikelid primary key, price)
tblbestallning(artikelid, amount)
I saw someone do this: select artikelid, sum(amount) as AmountSold from tblbestallning group by artikelID
this correctly showed the artikelid's and thee amount it has ever been bought
how do i multiply the times it has been bought with the price?
CodePudding user response:
This depends on the relationship between the two tables but assuming there is only one price per artikel, this would be a good starting point
SELECT tblbestallning.artikelid,
SUM(amount) as AmountSold,
SUM(amount*price) AS 'TotalSold'
FROM tblbestallning
JOIN tblartikel ON tblartikel.artikelid = tblbestallning.artikelid
GROUP by tblbestallning.artikelid