0

I have an csv importer for 3 files so that my game statistics can be updated quickly. After a while I realised it was inserting the same data into multiple columns in the database.

I am trying to update data inside one of the tables using an UPDATE statement.

The five columns I need fixed are data1, data2, data3, hits, totalnum.

If the user is a valid player then I need hits and totalnum set to 0.
If they are not a valid player than I need data1, data2 and data3 set to 0.

To check users valid I need to access users table and lookup the users details and check the is_valid column.

I may have to do 2 queries for this, 1 for valid users and 1 for non-valid users.

What I have so far doesn't check users table and i don't know how to do this.

UPDATE game_stats
SET data1 = 0,
data2=0,
data3=0
WHERE data1 <= 1 AND data2 <= 1 AND data3 <= 1

Users table
Id, fname, lname, is_valid, details

Game_stats
Id, userid, data1, data2, data3, hits, totalnum

Please could someone help me do this?

4

1 に答える 1

4

これにより、有効なユーザーが整理されます

UPDATE game_stats gs
SET gs.data1 = '0', gs.data2= '0', gs.data3= '0'
WHERE exists
(SELECT u.id
FROM users u 
WHERE u.is_valid='true' AND
u.id = gs.userid)

これにより、無効なユーザーが整理されます

UPDATE game_stats gs
SET gs.hits = '0', gs.totalnum = '0'
WHERE exists
(SELECT u.id
FROM users u
WHERE u.is_valid !='true' AND
u.id = gs.userid)

それが役立つことを願っています

于 2013-03-04T15:42:51.737 に答える