我正在尝试使用Method来获取表中分数的平均值。 我认为这很简单,但显然不是.. 它目前在下面
select avg(teamscore)
from team_table
where teamreviewed = (select ref(a) from game_table a where a.gameid=1000000)
我可以使用
获得平均值SELECT p.team_rating() from team_table p where p.teamreviewed = (select
ref(a) from game_table a where a.gameid=1000000)
但是下面只返回得分(在这种情况下是2和6)而不是平均得分。
String date = "2009-07-16T19:20:30-0500";
String pattern = "yyyy-MM-dd'T'HH:mm:ssZ";
我哪里错了?
答案 0 :(得分:0)
Object表示表中的一行。
成员函数:
MAP MEMBER FUNCTION team_rating RETURN NUMBER
IS
avg_score NUMBER;
BEGIN
SELECT AVG(TeamScore)
INTO avg_score FROM DUAL;
RETURN avg_score;
END;
使用DUAL
表 - 它有一行并取对象的TeamScore
属性的平均值 - 这是一个值 - 所以你的函数可以重写为:
MAP MEMBER FUNCTION team_rating RETURN NUMBER
IS
avg_score NUMBER;
BEGIN
RETURN TeamScore;
END;
目前还不清楚你想要平均的东西,但是:
MAP MEMBER FUNCTION team_rating RETURN NUMBER
IS
avg_score NUMBER;
BEGIN
SELECT AVG(TeamScore)
INTO avg_score
FROM Team_Table t
WHERE t.team = self.team;
RETURN avg_score;
END;
查询1 :
select avg(teamscore)
from team_table
where teamreviewed = (select ref(a) from game_table a where a.gameid=1000000)
<强> Results 强>:
| AVG(TEAMSCORE) |
|----------------|
| 4 |