Select Age,
(select avg(ShoeSize) from [dbo].[Transaction] t2 where t2.age = t1.Age and t2.ChildGender='Male') as avg_male,
(select avg(ShoeSize) from [dbo].[Transaction] t2 where t2.age = t1.Age and t2.ChildGender='Female') as avg_female
from [dbo].[Transaction] t1
group by Age ORDER BY Age
嗨,我有兩列avg_male和avg_female我如何取兩列的平均值並在第三列顯示。請幫助取兩列的平均值sql
看看我的答案。要做第三欄,您可以簡單地進行相同的平均計算,而不考慮where子句中的性別。 – TheOneWhoPrograms