Sum values from database

Hello everyone,

I have a database of equipment objects (like armors, weapons, etc) and I have a field “equiped” that can be true or false, according to the status of the object (equiped or not). Every object have many other fields with caracteristics (damage, armor, etc…).

In order to calculate total armor, damage, etc, from my character, I want to sum every caracteristics of the equiped items.

So I created some Number variables in my app, with SQL queries like this one :
SELECT SUM(“Armor”) FROM data WHERE “Equiped”==“true”

In the SQL window, it works fine, but when I go back to the app, the number value is always 0. How can I get these sums ? In a way that can be responsive, like if I equip a weapon, it will update automatically…

используйте CASE

SELECT * ,
CASE
WHEN Equiped == 'true' THEN  price - (price / 100) * discount
ELSE price
END totalPrice
FROM data LIMIT 0, -1

Maybe I’m just stupid, but it doesn’t give me the sum of all rows where “equiped” is true, right ? :no_mouth:

Sorry but I still don’t understand. In your video, we get the sum of the fields, but not the sum of the rows, right ?

SELECT pma_id, SUM(field1) FROM data LIMIT 0, -1
1 Like

Yes !!! It worked !! Thanks Vladimir, you’re definitly the best !

Maybe one day, I will understand why adding “pma_id” before the sum makes it work with flipabit, but it works ! :sweat_smile:


Back to Flipabit >
Copyright © 2018. Flipabit Team. All rights reserved.