通过count函数求课程数和人数,急急急啊
各位大侠我下面有段sql已经求出了我想要的数据集,但是我想要拿到里面的某些字段的个数。我试了很多办法都没有见效,无奈希望某位大侠能指点一下。
sql如下:
select
o.organizename,course.c_coursename,u.realname
from sk_user_organize organize,sk_organize o,les_course course,les_courseaccess ca
,sk_user u
where organize.userid = ca.c_accessobjid
and organize.organizeid = o.organizeid
and ca.c_courseid = course.c_courseid
and ca.c_accessobjid = u.userid
order by o.organizename
北京分公司 工会职工提案宣导 海涛
现在我想实现 ,求出 每个部门下的课程数 和 每个部门下有课程的人数
例如:后援中心建设办公室 每个部门下的课程数:4 ,每个部门下有课程的人数:2
请各位大侠指点一下,我这个sql应怎么改造
[解决办法]
select t.organizename "部门名称",count(distance t.c_coursename) "课程数",count(distance t.realname) "人数" from (
select o.organizename, course.c_coursename, u.realname
from sk_user_organize organize,
sk_organize o,
les_course course,
les_courseaccess ca,
sk_user u
where organize.userid = ca.c_accessobjidand
organize.organizeid = o.organizeidand
ca.c_courseid = course.c_courseidand
ca.c_accessobjid = u.useridorder) t group by t.organizename