我有两张桌子,
学生:
rollno | name
1 | Abc
2 | efg
3 | hij
4 | klm
出席:
name | date |status
Abc | 10-10-2013 | A
efg | 10-10-2013 | A
Abc | 11-10-2013 | A
hij | 25-10-2013 | A
我需要的输出是:
一些查询条件为“'10-09-2013'和'13-10-2013'之间的日期”
rollno| name |count
1 | Abc | 2
2 | efg | 1
3 | hij | 0
4 | klm | 0
我尝试使用:
SELECT p.rollno,p.name,case when s.statuss='A' then COUNT(p.rollno) else '0' end as count
from attendance s
right outer join student p
on s.rollno=p.rollno
where s.date between '10-09-2013' and '13-10-2013'
group by p.rollno,p.regno,p.name,s.statuss
order by p.rollno
输出是:
rollno| name |count
1 | Abc | 2
2 | efg | 1
我希望还附加学生表中的剩余值。我尝试了许多不同的查询,但都没有成功。是否有一个查询会返回上面所需的输出?