我有一张表格,代表玩过Flash游戏的用户的得分和ID。我想返回普通用户尝试游戏的次数 - 每次完成“尝试”时,用户的得分和id都输入到mysql表中。结构是 -
id int(11)
score int(11)
fb_id int(25)
这为我提供了每个用户的尝试次数
SELECT count(score) AS counted FROM `ifa_scores` GROUP BY `fb_id`
但我想要这样的东西
我想要总体上玩的平均次数 - 即具有相同FB_ID的平均行数
答案 0 :(得分:2)
SELECT AVG(t.counted)
FROM
(
SELECT COUNT(id) AS counted
FROM ifa_scores
GROUP BY fb_id
) AS t
答案 1 :(得分:1)
SELECT `fb_id`, avg(score) AS counted FROM `ifa_scores` GROUP BY `fb_id`
答案 2 :(得分:1)
你需要计算一下已玩过多少游戏,并计算玩家数量,将他们加在一起,然后适当划分;
之类的东西SELECT GAMES_PLAYED,
PLAYERS,
GAMES_PLAYED / PLAYERS AS AVERAGE_GAMES_PER_PLAYER
FROM
(SELECT COUNT(*) AS GAMES_PLAYED FROM 'ifa_scores') g,
(SELECT COUNT(*) AS PLAYERS FROM (SELECT DISTINCT 'fb_id' FROM 'ifa_scores')) p;
应该有效。或者你可以使用
SELECT AVG(GAMES_PLAYED) AS AVERAGE_GAMES_PER_PLAYER
FROM (SELECT FB_ID, COUNT(*) AS GAMES_PLAYED
FROM 'ifa_scores'
GROUP BY 'fb_id');
分享并享受。
答案 3 :(得分:1)
以下应该有效: count(*)返回每个用户玩的游戏数。平衡这个应该给你你正在寻找的答案。请检查
SELECT fb_id,avg(count(*))AS从ifa_scores
GROUP BY fb_id
计算