结合查询中的输出值

时间:2013-01-14 23:10:00

标签: mysql sql

如何结合输出值。我的查询下面有It.Finance下的3个值...假设高,中,低......我想将中低合并为平均值,这意味着我的输出值可能是

平均值(中等和低)

select  count(h.Dept_id) as DeptCount,

i.Id as CompanyId,

i.Account as AccountTotal,

i.Technology as IT,

ISNULL(it.Finance,'NoCapacity') as School

from Institution i left join 

 History h on h.Institution_id = i.Id left join 

   xxxxx

   yyyyy      

group by i.Id,i.Account,i.Technology,it.Finance

有可能吗?

1 个答案:

答案 0 :(得分:0)

最佳盲目猜测:

select  count(h.Dept_id) as DeptCount,
i.Id as CompanyId,
i.Account as AccountTotal,
i.Technology as IT,
coalesce(it.Finance,'NoCapacity') as School,
Max(it.Finance) as High, 
(Avg(it.Finance) + Min(it.Finance))/2 as Average
from Institution i left join 
History h on h.Institution_id = i.Id left join 
   xxxxx -- your unknown tables
   yyyyy -- your unknown tables     
group by i.Id, i.Account