计算平均值
CODE QTY TAXUP
PMA0100200018000.000015.93000000
PMA01002000455.000015.93000000
PMA0100200011869.000016.65000000
PMA01002000100.000015.72000000
PMA010020005624.000015.45000000
select sum(qty*taxup)/count(taxup) from TB where code = 'PMA01002000'
select code,sum(qty+taxup)/sum(qty) as col
from tb
where code = '...'
group by code
select code,sum(qty*taxup)/sum(qty)
from tb group by code
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (CODE nvarchar(22),QTY numeric(9,4),TAXUP numeric(10,8))
insert into [TB]
select 'PMA01002000',18000.0000,15.93000000 union all
select 'PMA01002000',455.0000,15.93000000 union all
select 'PMA01002000',11869.0000,16.65000000 union all
select 'PMA01002000',100.0000,15.72000000 union all
select 'PMA01002000',5624.0000,15.45000000
select * from [TB]
select sum(qty*taxup)/count(taxup) from TB where code = 'PMA01002000'
--116013.960000000000