-1

I have a database with a table called: products.

In this table I have 5 rows:

ID as int
Product as varchar
Type as varchar
KG as int
Price_KG as int

Now I want to make a dashboard where I can see the total value of a type product.

For example:

Click for preview

Now I want to see the total value of all type fruits together: (5x12)+(8*5)+(38*1)+(30*3)+(50*2)= 328

So the value what will display is 328.

Same as the type of groente or whatever it will be in the future.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • You should learn [`GROUP BY`](https://www.mysqltutorial.org/mysql-group-by.aspx/) and aggregate functions. They essentially allow one to summarize data by the selected field values. In your case fruitnames. – Nae Jan 10 '21 at 18:08
  • 1
    Please show us your work. What have you tried already? – Abbas Akhundov Jan 10 '21 at 20:50

1 Answers1

0
SELECT Type, SUM(KG * Price_KG) TotalValue
FROM products
GROUP BY Type
;

The mysql query above tells the total costs by each type of product.

Nae
  • 14,209
  • 7
  • 52
  • 79