帮忙写一句简单的sql语句,简直在送分~

来源:百度知道 编辑:UC知道 时间:2024/05/19 07:22:56
有这样一张表,是某球员每场比赛的数据。

比赛 数据类型 数据值
1 得分 10
1 篮板 5
1 助攻 2
1 首发 是
2 得分 20
2 篮板 8
2 助攻 3
2 首发 否
…………………………以此类推,类似这种表。

现在我要select出 某位球员首发情况下的(首发字段=是)的场均数据(得分,篮板,助攻的平均值)

要实现这样的功能,sql语句如何写。。。谢谢了!~ 我分不多,先给50分,如果答的好,我再加~~~谢谢了!~

--> --> (Roy)生成测试数据

if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([比赛] int,[数据类型] nvarchar(2),[数据值] nvarchar(2))
Insert #T
select 1,N'得分',N'10' union all
select 1,N'篮板',N'5' union all
select 1,N'助攻',N'2' union all
select 1,N'首发',N'是' union all
select 2,N'得分',N'20' union all
select 2,N'篮板',N'8' union all
select 2,N'助攻',N'3' union all
select 2,N'首发',N'否'union all
select 3,N'得分',N'20' union all
select 3,N'篮板',N'7' union all
select 3,N'助攻',N'5' union all
select 3,N'首发',N'是'
Go
Select
cast(sum(case when [数据类型]=N'得分' then [数据值] else 0 end)*1.0/count(distinct [比赛]) as decimal(18,2)) as 均场得分,
cast(sum(case when [数据类型]=N'篮板