View previous topic :: View next topic |
Author |
Message |
Alderaan
Joined: 29 Jan 2005 Posts: 3
|
Posted: Sat Jan 29, 2005 20:27 Post subject: What's wrong with my SQL statement |
|
|
OK, I have two factions and I want to sum the total Honor of each faction.
I store my player data under pwdata which looks like this:
Table: pwdata
tag name val
------ ------ -------
Player A FACTION CHAOS
Player A VILLAGE_HONOR 1000
Player B FACTION CHAOS
Player B VILLAGE_HONOR 800
Player C FACTION ORDER
Player C VILLAGE_HONOR 600
I want the total VILLAGE_HONOR for the CHAOS faction.
I run the following SQL querry
SELECT SUM(val) FROM pwdata WHERE name='VILLAGE_HONOR' AND tag IN (SELECT tag FROM pwdata WHERE val='CHAOS')
It isn't working. What am I doing wrong? and how can I correct this.
Thanks |
|
Back to top |
|
|
Manuel
Joined: 30 Dec 2004 Posts: 51
|
Posted: Sun Jan 30, 2005 2:21 Post subject: |
|
|
SUM() is for adding values together. You want to use COUNT(). _________________ I only know enough to be dangerous. |
|
Back to top |
|
|
Alderaan
Joined: 29 Jan 2005 Posts: 3
|
Posted: Sun Jan 30, 2005 2:56 Post subject: |
|
|
Adding the values is exatcly what I want. I want to get the total honor of each faction |
|
Back to top |
|
|
NoMercy
Joined: 03 Jan 2005 Posts: 123 Location: UK
|
Posted: Sun Jan 30, 2005 5:19 Post subject: |
|
|
Looking at it, apart from the horror of not having tables in a higher normal form, I guess your problem is most likely that your running SUM() on a text field. |
|
Back to top |
|
|
Manuel
Joined: 30 Dec 2004 Posts: 51
|
Posted: Sun Jan 30, 2005 18:55 Post subject: |
|
|
Yeah, that's what threw me so I assumed COUNT(). How does one SUM() 'CHAOS'? _________________ I only know enough to be dangerous. |
|
Back to top |
|
|
NoMercy
Joined: 03 Jan 2005 Posts: 123 Location: UK
|
Posted: Sun Jan 30, 2005 23:04 Post subject: |
|
|
I'm confused why it's not working because normalyl "1" = 1 in MySQL, might need to do something like 0+val so it knows to convert it into a number... |
|
Back to top |
|
|
|