declare @1 table([id] int,[公司] nvarchar(1),[数量] int,[值] int)
Insert @1
select 1,N'A',2,3 union all
select 2,N'A',3,4 union all
select 3,N'B',4,6 union all
select 4,N'B',3,5 union all
select 5,N'B',6,8 union all
select 6,N'C',8,5 union all
select 7,N'C',9,2 union all
select 8,N'C',5,4
Select [avg]=avg([值]) from @1 a
Where id=(Select Top 1 id From @1 Where [公司]=a.[公司] Order By [数量])
/*
avg
-----------
4
*/