Gossamer Forum
Home : General : Databases and SQL :

Any insight into Rolling Sums in SQL

Quote Reply
Any insight into Rolling Sums in SQL
I would like to get a running total and have read just enough to have a headache.

This is what I am thinking

User
prize amount

running total prize amount per user
running total prize dispensed


each user can play only once a day.

Any suggestions on "how to" would be appreciated.


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Any insight into Rolling Sums in SQL In reply to
Hi,

Depends on how you have it setup?

Doing a SUM is pretty simple.

Stuff like:

Code:
SELECT SUM(FielName) FROM Table WHERE Whatever = "Whatever"

..or in GLinks, you can do with:

Code:
my $total = $DB->table('Links')->select( ['SUM(FieldName)'], { Whatever => "whatever" } )->fetchrow;

Without knowing more on how you have your site setup, not a lot more I can suggest :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Any insight into Rolling Sums in SQL In reply to
Hey Andy,

Can you tell I am advancing my get in trouble level? LOL


this is what I started with
Code:

print ("Date $row[dayt]|<a href=mailto:$row</a>|");
if ($winner == 1)
print ("prize 1");
else if ($winner == 2)
print ("prize 2");
else if ($winner == 3)
print ("prize 3");
else if ($winner == 4)
print ("prize 4");
print ("|$winner Match|");
print ("USD|Ticket-$row[ticket]|Message<br>\n");

I am wanting the if statements to provide a running total per player.
I was thinking it would be easier if the database did the running total,
then simply print that total, what do you think?


If a player, played 3 times in a week I could get a running total of the players winnings.

Last edited by:

SandraR: Oct 2, 2009, 12:11 AM
Quote Reply
Re: [SandraR] Any insight into Rolling Sums in SQL In reply to
Hi,

Sorry, still not really enough info to be able to give a decent answer =)

1) What "field" is the prize held in?
2) Is the prize field actually "money"? (i.e so it can be totalled up)
3) Can you show a bit more of the code you just sent, with the SQL query you are using to grab the data.

That may help a bit more :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Any insight into Rolling Sums in SQL In reply to
Andy wrote:
Hi,

Sorry, still not really enough info to be able to give a decent answer =)

1) What "field" is the prize held in?
2) Is the prize field actually "money"? (i.e so it can be totalled up)
3) Can you show a bit more of the code you just sent, with the SQL query you are using to grab the data.

That may help a bit more :)

Cheers

1) What "field" is the prize held in?
Its not held in a field as its a comparision.

2) Is the prize field actually "money"? (i.e so it can be totalled up)
Yes it is money

3) Can you show a bit more of the code you just sent, with the SQL query you are using to grab the data.
Code:
$result = mysql_db_query ($DBName, $query, $Link);
while ($row = mysql_fetch_array($result)){
if ($row[ticket] == "$ticketnumber"){
// Find how many match
if ($row[1] == $row[you1]){
$winner = $winner + 1;
}
if ($row[2] == $row[you2]){
$winner = $winner + 1;
}
if ($row[3] == $row[you3]){
$winner = $winner + 1;
}
if ($row[4] == $row[you4]){
$winner = $winner + 1;
}
Quote Reply
Re: [SandraR] Any insight into Rolling Sums in SQL In reply to
Ah, is this PHP? Afraid I havn't dabbled with that in years =)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Any insight into Rolling Sums in SQL In reply to
I thought it was more of a mysql dbase running total issue and not so much a php issue.. that's what I get for thinking.

thanks so much for your help it is always appreciated.