目前我忙于两张桌子,学生和课程。这两个都包含一个列 project_group ,这是一种将多个学生从一个班级分类为较小组的方法。
在学生表格中有一列城市,用于说明哪些城镇/城市学生居住,从已填充的行中已经有多个城市出现多个倍。我用来检查城市展示次数的代码是:
SELECT City, count(*)
FROM Students
GROUP BY City
现在我要做的下一件事就是按班级展示学生居住的城市和居住的城市,例如结果如下:
学生和 Classes 可以在列 project_group 上相互加入,但我最感兴趣的是他使用前面提到的GROUP BY ,使用 JOIN 并显示每个类的结果。
提前致谢, 拉德
答案 0 :(得分:0)
我不确定示例中A和B的列名是什么。我在下面假设Classes.Class:
s=0
答案 1 :(得分:0)
I managed to get it working. While doing some tests to see which exact error message it was that I got, I used this and managed to get it working. I now get an overview per class that shows how many people live in which city. This is the code used.
SELECT class_id, city, count(*) AS amount
FROM students, classes
WHERE students.project_group = classes.project_group
GROUP BY class_id, city
ORDER BY class_id