I am trying to make a mock database that displays the equipment data for three separate game characters. When I run the following SQL I am able to pull up the full table
SELECT customerID, characters.characterID, characterName, headName, chestName, legsName, armsName
FROM characters
JOIN character_equipmentv ON characters.characterID = character_equipment.characterID
JOIN gear_head ON character_equipment.headID = gear_head.headID
JOIN gear_chest ON character_equipment.chestID = gear_chest.chestID
JOIN gear_legs ON character_equipment.legsID = gear_legs.legsID
JOIN gear_arms ON character_equipment.armsID = gear_arms.armsID
ORDER BY characterID
However when I add the SUM function to get the character’s gearscore:
SUM(gear_head.gearScore + gear_chest.gearScore + gear_legs.gearScore + gear_arms.gearScore) AS gearScore
To the end of my SELECT statement, it only displays the first entry with the combined gearscore for every character! How can I fix this?
Check out SQL Grouping.
Okay:
SUMis an aggregate function and requires aGROUP BYclause to produce meaningful results based on another column.