日期:2014-05-17 浏览次数:20750 次
CODE QTY TAXUP
PMA01002000 18000.0000 15.93000000
PMA01002000 455.0000 15.93000000
PMA01002000 11869.0000 16.65000000
PMA01002000 100.0000 15.72000000
PMA01002000 5624.0000 15.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