纪念一下

工作快一年了。sql越写越长了。纪念一下。

 

 SELECT distinct tcourse.course_name 学科,
          (select count(distinct tcam.user_id)
             from lasun_qinghai.train_class_assistant_map tcam
            where tcam.class_id in
                  (select tc.class_id
                     from lasun_qinghai.train_class tc
                    where tc.course_id = tcourse.course_id)) 教师数,
          (select count(btopic.topic_id)
             from bbs_qinghai.bbs_topic btopic
            where btopic.data_5 = tcourse.course_id) +
          (select count(breply.reply_id)
             from bbs_qinghai.bbs_reply breply
            where breply.data_5 = tcourse.course_id) 总贴数,
          (select count(btopic.topic_id)
             from bbs_qinghai.bbs_topic btopic
            where btopic.data_5 = tcourse.course_id
              and btopic.cre_user_type <> 'train.usertype.Student') +
          (select count(breply.reply_id)
             from bbs_qinghai.bbs_reply breply
            where breply.data_5 = tcourse.course_id
              and breply.cre_user_type <> 'train.usertype.Student') 总辅导贴数,
          (select count(btopic.topic_id)
             from bbs_qinghai.bbs_topic btopic
            where btopic.data_5 = tcourse.course_id
              and btopic.cre_user_type <> 'train.usertype.Student'
              and (to_char(btopic.cre_time, 'yyyy-MM-dd HH:mm:ss') between
                  to_char(sysdate, 'yyyy-mm-dd') || ' 00:00:00' and
                  to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59')) +
          (select count(breply.reply_id)
             from bbs_qinghai.bbs_reply breply
            where breply.data_5 = tcourse.course_id
              and breply.cre_user_type <> 'train.usertype.Student'
              and (to_char(breply.cre_time, 'yyyy-MM-dd HH:mm:ss') between
                  to_char(sysdate, 'yyyy-mm-dd') || ' 00:00:00' and
                  to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59')) 今日辅导贴数,
          (select count(hcommit.commit_id)
             from homework_qinghai.homework_commit hcommit
            where hcommit.data_5 = tcourse.course_id
              and hcommit.homeworkcommit_state = '3') 已批作业数,
          (select count(hcommit.commit_id)
             from homework_qinghai.homework_commit hcommit
            where hcommit.data_5 = tcourse.course_id
              and hcommit.homeworkcommit_state = '2') 待批作业数,
          (select count(hcommit.commit_id)
             from homework_qinghai.homework_commit hcommit
            where hcommit.data_5 = tcourse.course_id
              and hcommit.homeworkcommit_state = '3'
              and (to_char(hcommit.commit_time, 'yyyy-MM-dd HH:mm:ss') between
                  to_char(sysdate, 'yyyy-mm-dd') || ' 00:00:00' and
                  to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59')) 今日批作业数
   FROM lasun_qinghai.TRAIN_CENTER    TCENTER,
        lasun_qinghai.CORE_DEPARTMENT D1,
        lasun_qinghai.train_class     tclass,
        lasun_qinghai.train_course    tcourse
  WHERE TCENTER.DEPARTMENT_ID = D1.DEPARTMENT_ID
    and tcourse.course_name like '%60%'
    AND tclass.center_id = tcenter.center_id
    and tcourse.course_id = tclass.course_id
    AND D1.Department_code like '002053%';
 

 

你可能感兴趣的:(sql,工作,bbs)