表1
编号 得分 类别编号
1 90.5 1
1 88 1
2 95 2
2 90 3
2 87.5 2
...................表2
类别编号 占总分值百分比
1 80
2 10
3 10要求表1 按编号分组统计合计实际得分数。要考虑表2中所占百分比。
编号 得分 类别编号
1 90.5 1
1 88 1
2 95 2
2 90 3
2 87.5 2
...................表2
类别编号 占总分值百分比
1 80
2 10
3 10要求表1 按编号分组统计合计实际得分数。要考虑表2中所占百分比。
from 表1 as a inner join 表2 as b on a.类别编号=b.类别编号
group by a.编号
from 表1 a,表2 b
where a.类别编号=b.类别编号
group by a.编号
from 表1 as a inner join 表2 as b on a.类别编号=b.类别编号
group by a.编号
select 得分*b.占总分值百分比/100.0,a.类型编号
from
(select 得分=sum(得分),类别编号 from 表1
group by 类型编号)a
inner join 表2 b on a.类型编号=b.类型编号
(
编号 int,
得分 decimal(4,1),
类别编号 int
)
create table 表2
(
类别编号 int,
占总分值百分比 int
)insert into 表1 select 1,90.5,1
insert into 表1 select 1,88,1
union all select 2,95,2
union all select 2,90,3
union all select 2,87.5,2
insert into 表2 select 1,80
union all select 2,10
union all select 3,10
select 实际分数=t3.总得分*t1.占总分值百分比/100 from 表2 t1,(select 类别编号,总得分=sum(得分) from 表1 group by 类别编号)t3 where t1.类别编号 = t3.类别编号
drop table 表1,表2
/*
实际分数
----------------------------------------
142.800000
18.250000
9.000000(所影响的行数为 3 行)
*/
where c.类别编号=b.类别编号
表1 a
表2 b