Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a data table with 3 columns like below:
Item1 Item2 Value
Apple Orange 3
Apple Banana 2
Mango Apple 2
Banana Apple 6
Apple Mango 5
Orange Banana 4
Orange Apple 5
I want to remove the duplicate rows based on the combinations of two columns Item1 & Item2 and show only one in any order and want to add their values as a result, so as the final output in my table box can be:
Item1 Item2 Value
Apple Orange 8
Apple Banana 8
Mango Apple 7
Orange Banana 4
Thank you for any help or attention ! or at least can any one answer me if its even possible to do that !!
This is my solution :
SELECT LEAST(Item1, Item2) AS Item1, GREATEST(Item1, Item2) AS Item2, SUM(Value) AS Value FROM yourTable GROUP BY 1, 2;
This is my solution :
SELECT LEAST(Item1, Item2) AS Item1, GREATEST(Item1, Item2) AS Item2, SUM(Value) AS Value FROM yourTable GROUP BY 1, 2;