我想提出一個SQL查詢來顯示每個用戶的多個用戶的分數,也應該給avarage明星特定用戶已經achived一個高分榜,和MAX水平達到的,也是我想提出的總時間用戶在遊戲中通過總結每個級別的所有花費的時間計算..
我有以下問題:
1:我的SQL查詢不會給我每個用戶一行。
2:被ginving的總和是不是每個用戶,但所有的用戶的總和。
3:avarage STARS不與小數顯示。
4:我不能得到「score.time_spent」來計算的所有特定用戶已經打
我的SQL查詢在pressent時間的時間總和看起來像這樣:
SELECT DISTINCT
game_users.username AS 'User Name',
'Level Reached' = (SELECT DISTINCT MAX(score.game_level) FROM score
WHERE score.game_users_id IN
(SELECT game_users_id FROM game_users
WHERE game_users.id = score.game_users_id)),
score.time_spent AS 'Total Time Spent',
'Stars' = (SELECT DISTINCT AVG(score.stars) FROM score
WHERE score.game_users_id IN
(SELECT game_users_id FROM game_users
WHERE game_users.id = score.game_users_id)),
'High Score' = (SELECT DISTINCT SUM(score.game_level_score) FROM score
WHERE score.game_users_id IN
(SELECT game_users_id FROM game_users
WHERE game_users.id = score.game_users_id)),
game_users.current_state AS 'Online State'
FROM
game_users
INNER JOIN score ON game_users.id = score.game_users_id
GROUP BY
game_users.id,
game_users.username,
score.game_level_score,
score.game_level,
score.time_spent,
score.stars,
game_users.current_state
GO
的 「game_users」 表看起來像這樣:
id int Unchecked
firstname varchar(100) Checked
lastname varchar(100) Checked
email varchar(100) Checked
username varchar(50) Checked
usr_pass varchar(50) Checked
current_state int Checked
的「分數」表看起來像這樣:
id int Unchecked
game_users_id int Unchecked
game_level varchar(4) Checked
game_level_score numeric(18, 0) Checked
stars int Checked
time_spent time(7) Checked
有人可以幫助我走出這個爛攤子? :-)
問候
斯蒂格:-)
謝謝你的回答:-)諾拉,你有100%解決了所有問題,我實際上可以複製/粘貼腳本,它可以工作輝煌! 太感謝你了:-) /斯蒂格:-) – Stkol76 2012-02-02 20:13:14
非常感謝你。請接受業績獎勵的答案(複選標記)。 :) – 2012-02-02 20:42:02