聚合函数'count'未返回预期结果

时间:2018-03-23 01:46:12

标签: mysql sql database

我使用mySQL查询模拟大学数据库。这是一个类。我想要提出的问题是这个问题:

  

找到完全取一个的学生的姓名和ID   当然是在2010年春季学期。

架构表:

学生(id,name,dept_name,total_cred)

需要(id,course_id,sec_id,semester,year,grade)

我可以查询2010年春季上课的所有学生的架构没问题。但是我遇到麻烦的地方就是“正是一个阶级”的部分。

from ftplib import FTP

ip = raw_input("Enter ip: ")
user = open("usss.txt","r") 
passw = open("passs.txt","r")

us = user.readlines()
pa = passw.readlines()


conection = FTP(ip)
state_ftp = conection.login(us, pa)
print state_ftp
print "[+]CONECTION SUCCESSFUL!"

我以为我会使用像select distinct s.id, name from student s join takes where semester = 'Spring' and year = 2010; 这样的集合运算符将该结果与另一个结果进行比较,以返回每个学生所选课程的数量:

not in

问题是,当我运行此查询时,它会为每个名称返回8的计数。但我不知道它在哪里获得这个数字,因为没有任何事情恰好发生了8次。

我的问题:

1)我是以正确的方式进行此事吗?

2)如果是这样我做错了什么让计数以这种方式回归?

1 个答案:

答案 0 :(得分:1)

试试这个:

public static List<List<int>> SplitOnList(List<int> toSplit, List<int> splitBy)
{
    // Argument validation omitted (check for null and Lengths are equal)

    var results = new List<List<int>>();
    var singleResult = new List<int> {toSplit[0]};

    var lastIndex = splitBy.IndexOf(toSplit[0]);

    for (int i = 1; i < toSplit.Count; i++)
    {
        var thisItem = toSplit[i];
        var thisIndex = splitBy.IndexOf(thisItem);

        if (thisIndex > lastIndex)
        {
            singleResult.Add(thisItem);
        }
        else
        {
            results.Add(singleResult);
            singleResult = new List<int> { thisItem };
        }

        lastIndex = thisIndex;
    }

    results.Add(singleResult);

    return results;
}