Issue
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:
how to calculate the quantity of mangoes and apples that have been taken?
Solution
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;
Answered By – Harshit Rathore
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0