OK, here's something complex that I am doing (complex for me, mostly not for y'all who've been doing this for a while).
I want to have a table in which I am indexing a person name, userID, pass, points earned on a game. Now over the course of 5 months, let's say we have 10 games.
What I wish to do is find an average after each game has been played. Supposing all gamesa re worth 100 points each, and if the person got 56 in the first game and 98 in the next, his total would be 56+98/2. And that is the number I wish to display when the person logs in to his account.
Now, I have the login and all setup, and I also have the database setup with one table that deals with the name, userID, and "expectedpoints" and "achievedpoints"
原帖地å€: TechSpott - Computer and technology forums http://www.techspott.com//showthread.php?p=6491
The problem is, I cannot have a single table and keep on inputting scores from different games into a given row that has columns corresponding to a person named, Joe, let's say, or someone else.
So I'd have to join two tables for this purpose, wouldn't I? So, how would I join the two tables, and how would the structure of my second MySQL table look like if I wanted to have 10 rows (or colums?) for the 10 games that Joe would play, and then, average it out? I know that SUM(points) doesn't apply to rows so I would have to have an entire column which will display the points earned solely by Joe, and then select that column. But how do I select that column, I mean how would I set up a primary key for a column to distinguish it from the rest that "this column belongs to Joe and all the points have to be tallied only for Joe cuz he's the guy that has just logged in"?
Again, in a simpler way, I just wish to echo (not literally as is given-->) "sum(achievedpoints) / COUNT(*) achievedpoints FROM points)", but from my table which would contain numerous people's points, how do I point out to the one that deals with Joe's points when Joe logs in and wants to see his points?
Uh, I hope I was clear. REALLY thanks for any, any, _any_ help that I will receive!