我正在尝试找出此查询,这使我感到困惑。目标是创建一个要显示的SQL查询:Scholarship_Name,授予的平均金额。我将链接下面的表格以及我到目前为止所做的查询,希望有人可以指出我在做什么错。
我想指出的是,这两个表没有任何相同的PK或FK,所以这就是为什么我以自己的方式链接它们的原因。到目前为止,我在查询中所做的工作都显示了名称,但是当我尝试对数量进行平均时,它们将变为0.0。我很沮丧,整天都在搜寻。任何帮助,将不胜感激。
奖学金
ID / SCHOLARSHIP_NAME / AMOUNT_AVAILABLE
"1" "Presidents Award" "$15,000"
"2" "Chancellor Academic Award" "$25,000"
"3" "Chevron Award" "$20,000"
SCHOLARSHIP_AWARDS
ID / SCHOLARSHIP_ID / STUDENT_ID / AMOUNT_AWARDED
"1" "2" "9" "$1,500"
"2" "3" "8" "$1,500"
"3" "1" "7" "$2,000"
"4" "2" "6" "$1,500"
"5" "2" "5" "$3,000"
"6" "3" "4" "$5,000"
"7" "3" "3" "$2,500"
"8" "2" "2" "$2,500"
"9" "1" "1" "$1,500"
查询:
SELECT Scholarships.SCHOLARSHIP_NAME, AVG(Scholarship_Awards.Amount_Awarded) AS "Average Amount Awarded"
FROM Scholarships JOIN Scholarship_Awards
ON Scholarship_Awards.SCHOLARSHIP_ID = SCHOLARSHIPS.ID
GROUP BY SCHOLARSHIP_NAME