0

I am creating a game and stuck at this and can't figure it out. I am storing all player information in a MYSQL database.

PLAYER|LOCATION|RESOURCEA|RESOURCEB|B1Buildings|B2Buildings

How can I update/increment RESOURCEA as a function of # in B1Buildings in a loop for all players as a SQL function given that different players may have different number of B1Buildings?

ie. B1Buildings = 2, B1Rate=2x per ServerLoop, ResourceA =ResourceA+b1Rate*b1building

4

1 回答 1

0

I don't think you really need a loop. Your requirement is not stated very clearly. At least, I'm not able to decipher exactly what it is you want to accomplish. (Where is B1Rate coming from?)

I'm going to assume that PLAYER is a unique identifier for a row in your table.

In that case, a simple UPDATE statement would suffice if you can supply a value for B1Rate in the statement:

UPDATE mytable t SET t.RESOURCEA = t.RESOURCEA + 2 *t.B1Buildings
于 2013-11-03T02:59:28.547 回答