2013-01-14 20 views
0

如何組合輸出值。我有我的查詢低於It.Finance下3個值...假設高,中,low..i希望中,低相結合的平均值,這意味着我的輸出值可以組合輸出值ina查詢

平均(對於中等和低)

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 

是否有可能?

+0

你可以稍微更具體一點與解釋,或者更確切地說,我們展示了一些樣本數據表架構,並基於該預期輸出..: ) – bonCodigo

回答

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 
+0

@ bonCodigo.thanks for your reply.its不計算平均值它只是將中間值和低值組合成一個名稱Average ... –