Home > front end >  How to Count data with different column variables in SQL
How to Count data with different column variables in SQL

Time:10-05

I want to ask about how to count the number of data with several different variables in a column, for example I have data like this:

Example Data

how to calculate the quantity of mangoes and apples that have been taken?

CodePudding user response:

You can use group by clause and then can apply sum function over it.

Select Item, Sum(Quantity) from TableName group by Item;

and to rename the new column you can use as

Select Item, Sum(Quantity) as 'Total' from TableName group by Item;

to get only quantity of mangoes and apples you can use where clause

Select Item, Sum(Quantity) as 'Total' from TableName where Item in ('Apple', 'Mango') group by Item;
  • Related