logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
What's wrong with my SQL statement

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
Alderaan



Joined: 29 Jan 2005
Posts: 3

PostPosted: Sat Jan 29, 2005 20:27    Post subject: What's wrong with my SQL statement Reply with quote

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
View user's profile Send private message
Manuel



Joined: 30 Dec 2004
Posts: 51

PostPosted: Sun Jan 30, 2005 2:21    Post subject: Reply with quote

SUM() is for adding values together. You want to use COUNT().
_________________
I only know enough to be dangerous.
Back to top
View user's profile Send private message
Alderaan



Joined: 29 Jan 2005
Posts: 3

PostPosted: Sun Jan 30, 2005 2:56    Post subject: Reply with quote

Adding the values is exatcly what I want. I want to get the total honor of each faction
Back to top
View user's profile Send private message
NoMercy



Joined: 03 Jan 2005
Posts: 123
Location: UK

PostPosted: Sun Jan 30, 2005 5:19    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Manuel



Joined: 30 Dec 2004
Posts: 51

PostPosted: Sun Jan 30, 2005 18:55    Post subject: Reply with quote

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
View user's profile Send private message
NoMercy



Joined: 03 Jan 2005
Posts: 123
Location: UK

PostPosted: Sun Jan 30, 2005 23:04    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group