我对SQL很陌生,并且在处理某些事情时遇到了很多麻烦。以下代码
SELECT Treated.ProgScore, Patient.Ethnicity
FROM Patient
JOIN City
ON Patient.ZIP = City.ZIP
JOIN Treated
ON Patient.SSN = Treated.PSSN
WHERE City.Cname != 'Dallas';
生成以下数据。我想提取每个种族的平均ProgScore,并从最低到最高的平均ProgScore列出
PROGSCORE INHNICITY
2 Japanese
5 Caucasian
9 Caucasian
2 African
3 Japanese
7 Caucasian
10 Japanese
8 Caucasian
1 African
4 Japanese
7 Caucasian
有办法做到这一点吗?我希望我的输出看起来像这样。
平均民族
4.75 Japanese
7.2 Caucasian
感谢您的帮助
答案 0 :(得分:1)
这听起来像你想要的
SELECT avg(Treated.ProgScore), Patient.Ethnicity
FROM Patient
JOIN City
ON Patient.ZIP = City.ZIP
JOIN Treated
ON Patient.SSN = Treated.PSSN
WHERE City.Cname != 'Dallas'
GROUP BY Patient.Ethnicity
ORDER BY avg(Treated.ProgScore);