我已经完成了从表格中创建统计数据的任务:
Faculty
1 FacultyName1
2 FacultyName2
3 FacultyName3
4 FacultyName4
5 FacultyName5
和此:
Student
1 StudentName1 FacultyNr2
2 StudentName2 FacultyNr3
3 StudentName3 FacultyNr5
4 StudentName4 FacultyNr2
现在我必须创建一个统计数据,将学院分组为新创建的字段和组。
说:
Faculty Group 1 Count: 3
Faculty Group 2 Count: 1
这个例子可以说, FacultyName1,FacultyName2,FacultyName3 的所有内容都应该从“Faculty Group 1”和 FacultyName4和FacultyName5 一直听到“Faculty Group” 2" 。
我开始做以下事情:
Select Count(*)
FROM Student INNER JOIN Faculty on Student.FacultyID = Faculty.ID
但我很难理解如何分组,如何在代码中创建群组,我可以说:Group by FacultyGroups (Select Case When FacultyName = 'FacultyName1' = 'Faculty Group 1')
或类似的东西,有人有任何想法吗?
答案 0 :(得分:1)
假设您已在Faculty表中添加了GroupID列
SELECT COUNT(*), f.GroupID
FROM Student AS s
INNER JOIN Faculty AS f ON s.FacultyID = f.ID
GROUP BY f.GroupID
它为您提供每组学院的学生人数和该组的ID
答案 1 :(得分:0)
有更好的方法,但这应该有效:
package sample.com.sample_project_2;
import android.test.ActivityInstrumentationTestCase2;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
public class ApplicationTest2 extends ActivityInstrumentationTestCase2<SecAct> {
public ApplicationTest2() {
super(SecAct.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testFoo2() {
onView(withId(R.id.editTextUserInput)).perform(typeText("SAMPLE 2"));
}
}
如果你的&#34;组&#34;逻辑变得太长,然后它会在你的查询中看起来很乱,所以你可能想要预先计算它。例如,您可以通过使用子查询来完成此操作,因此您的查询的一部分(子查询)会将系统转换为组,而另一部分将转换为#34; main&#34;部分将计算每组学生。