问题
I don't know why below codes did not work.
Problem: Using INNER JOIN, find the minimum “Average Student Attendance” for a community is where hardship is 96
SELECT b.Community_Area_Name, min(b.Average_Student_Attendance) FROM CENSUS_DATA as a
INNER JOIN CHICAGO_PUBLIC_SCHOOLS as b
ON a.Community_Area_Number =b.Community_Area_Number
WHERE a.hardship_index=96
GROUP BY b.Community_Area_Name
Error in jupyter notebook:
File "", line 2 INNER JOIN CHICAGO_PUBLIC_SCHOOLS as b ^ SyntaxError: invalid syntax
Error in SQL server:
"A.COMMUNITY_AREA_NUMBER" is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.22.36
回答1:
I have the same problem. I managed to it. The problem was described in article "work with real data set" week 4. We need use double quotes in our queries. Something like this
SELECT MIN("Average_Student_Attendance")
回答2:
Doublequotes will solve your problem, but what i found is when i doublequote Hardship_Index, i got error. But below code works on Jupyter.
%sql select min(PS."Average_Student_Attendance"), CD.Hardship_Index from CENSUS_DATA as CD INNER JOIN CHICAGO_PUBLIC_SCHOOLS as PS ON CD."Community_Area_Number" =PS."Community_Area_Number" WHERE CD.Hardship_Index = 96 GROUP BY CD.Hardship_Index
回答3:
Lists in SQL are is in ascending order by default so you do not need to use the minimum function to solve this query. I was able to solve this problem with the following WHERE statement.
WHERE C."HARDSHIP_INDEX"=96 ORDER BY S."Average_Student_Attendance" LIMIT 1;
来源:https://stackoverflow.com/questions/52520752/need-help-inner-join-and-where-condition