sql 求平均值,麻烦帮解决下

巨应打字员 2009-12-17 05:59:08
这么一张表

teamId(队伍id) playerId(球员id) vId(比赛id) date(比赛时间) score(得分)
2 1 1 2009/2010 3
4 2 1 2009/2010 5
3 5 7 2009/2010 5
2 1 3 2008/2009 11
1 4 4 2009/2010 1.5
6 5 5 2009/2010 2
5 1 1 2009/2010 1
4 1 1 2009/2010 3
3 1 1 2009/2010 3

我要查询指定teamId,playerId所有时间段的 score平均分

比如 2009/2010的平均分
2008/2009的平均分

怎么写?麻烦大家帮帮忙
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbihss 2009-12-17
  • 打赏
  • 举报
回复
每个球员所有赛事的平均得分
select
teamId,playerId,avg(score)
from
tb
group by
teamId,playerId

貌似一年也就一场赛事.
--小F-- 2009-12-17
  • 打赏
  • 举报
回复
select
date,teamId,playerId,avg(score) as score
from
tb
group by
date,teamId,playerId
ACMAIN_CHM 2009-12-17
  • 打赏
  • 举报
回复
select avg(score)
from 这么一张表
where teamId=xx and playerId = yyy
十一文 2009-12-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xming4321 的回复:]
SELECT AVG(score) FROM TB GROUP BY date Where teamId = 1 And playerId =2
[/Quote]
汗 group by 和 where次序反了
nianran520 2009-12-17
  • 打赏
  • 举报
回复

select date,teamId,playerId,avg(score) as score
from tb
group by date,teamId,playerId
十一文 2009-12-17
  • 打赏
  • 举报
回复
SELECT AVG(score) FROM TB GROUP BY date Where teamId = 1 And playerId =2
黄_瓜 2009-12-17
  • 打赏
  • 举报
回复

select teamId,playerId,avg(score) from @tb where date='2009/2010'
and teamId='指定队伍'
and playerId='指定球员'
group by teamId , playerId

?
SQL77 2009-12-17
  • 打赏
  • 举报
回复
SELECT teamId,playerId,AVG(score) FROM TB GROUP BY teamId,playerId
>

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧