计算平均值
CODE QTY TAXUPPMA01002000 18000.0000 15.93000000PMA01002000 455.0000 15.93000000PMA01002000 11869.0000 16.65000000PMA01002000 100.0000 15.72000000PMA01002000 5624.0000 15.45000000
select sum(qty*taxup)/count(taxup) from TB where code = 'PMA01002000'
[解决办法]
select code,sum(qty+taxup)/sum(qty) as colfrom tbwhere 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]gocreate table [TB] (CODE nvarchar(22),QTY numeric(9,4),TAXUP numeric(10,8))insert into [TB]select 'PMA01002000',18000.0000,15.93000000 union allselect 'PMA01002000',455.0000,15.93000000 union allselect 'PMA01002000',11869.0000,16.65000000 union allselect 'PMA01002000',100.0000,15.72000000 union allselect 'PMA01002000',5624.0000,15.45000000select * from [TB]select sum(qty*taxup)/count(taxup) from TB where code = 'PMA01002000'--116013.960000000000