我运行此查询:查询结果不是我想要的
select distinct(course.course) as course, count(students.studentid) as adm1,
count(cclogs.newstudentid) from course
left join students on (course.c_id=students.course and students.doa='2013-07-06')
left join cclogs on (cclogs.newcid=course.c_id and doc='2013-07-06' and
students.studentid=cclogs.newstudentid)
where course.exampattern='2'
group by course.c_id
现在我有三个表,学生,课程和CClogs。
我想要的是,课程表中的所有课程,在学生表中以及cclogs中录取的学生。但是当使用这个students.studentid = cclogs.newstudent时,coloum count(cclogs.newstudent)没有结果。任何想法 ?
的表是这样的:
场
C_id | Name
1 Abc
2 Bcd
学生
Studentid | DOA | course
1a 2013-07-05 Abc
2a 2013-07-05 Bcd
3a 2013-07-05 Bcd
4a 2013-07-06 Abc
5a 2013-07-05 Bcd
6a 2013-07-06 Abc
CClogs
id | newstudentid | oldstudentid | DOC | newcourse
1 1b 1a 2013-07-06 Bcd
2 5b 5a 2013-07-06 Abc
现在,当我运行查询,假设我要产生的2013-07-06然后结果应该是这样的:
Course | adm1 | newstudentid
Abc 2 1
Bcd 1 1
不确定它是否相关,但不需要'DISTINCT'修饰符。 'GROUP BY course.c_id'应该这样做。 – Barmar
您可以添加一些示例数据和期望的结果,并制作一个我们可以尝试的sqlfiddle? – Barmar
你能提供一些样本数据和你想要的结果吗?这也有助于解释为什么这是不正确的。 –