【发布时间】:2019-07-01 09:50:01
【问题描述】:
我正在尝试使用玩家姓名逐行显示每个玩家的平均值 我查看了整个 oracle 文档以及其他人在堆栈溢出时提出的先前问题。我只遇到过如何通过记录 id 选择平均值组以及如何使用子查询选择平均值
举个例子, 我发现是通过
得到每一行的平均值select round(avg(g1+g2+g3+g4)) as "Average Score" from ch_user group by playerid;
如果我选择 player 和 avg ,它会给我 ORA-01427。
我试过了
select player, (select round(avg(g1+g2+g3+g4)) from ch_user group by playerid) as "Average Score" from ch_user;
但它提示错误 ORA-01427。
单行子查询返回多行。
提前谢谢你
更新
我已经找到了问题的解决方案,并且我能够根据@Boneist 的回答将其实施到我的查询中。
但是,我发现查询很长,是否有机会简化查询?
我的查询是
select first_name || ' ' || last_name as Player,game_1 as G1 , game_2 as g2 ,
game_3 as g3, game_4 as G4,total_score as "Total Tournament Score",
round(avg(game_1+game_2+game_3+game_4)) as "Average Score" from ch_user
group by playerid, first_name,last_name,game_1,game_2,game_3,game_4,total_score;
【问题讨论】:
-
select MAX(PLAYER), round(avg(g1+g2+g3+g4)) as "Average Score" from ch_user group by playerid;-- 希望playerid为主键。