对呀!
他的表结构是这样的!
字段名     类型   长度   
jd_id    int    4     0
jd_startdate datetime 8     0
jd_enddate  datetime 8     0
jd_start   bit    1     1
jd_select   bit    1     1

解决方案 »

  1.   

    select a.sgs_id,c.cla_name,d.cou_name,e.tea_name,
    sum(case when f.jd_select=0 then jf_grades
    else jf_yesno end)
    from 
    tb_judgefile a,
    tb_classcourse b,
    tb_class c,
    tb_course d,
    tb_teacher e,
    tb_judgedate f 
    where a.jt_tc_id=b.jt_tc_id
    and b.cla_id=c.cla_id
    and b.cou_id=d.cou_id
    and b.tea_id=e.tea_id
    group by a.sgs_id,c.cla_name,d.cou_name,e.tea_name,
      

  2.   

    基本上是表联接问题,大体这样,不对你修改一下:
    select a.sgs_id,c.cla_name,d.cou_name,e.tea_name,
    sum(case when f.jd_select=0 then jf_grades
    else jf_yesno*1 end)
    from 
    tb_judgefile a,
    tb_classcourse b,
    tb_class c,
    tb_course d,
    tb_teacher e,
    tb_judgedate f 
    where a.jt_tc_id=b.jt_tc_id
    and b.cla_id=c.cla_id
    and b.cou_id=d.cou_id
    and b.tea_id=e.tea_id
    group by a.sgs_id,c.cla_name,d.cou_name,e.tea_name
      

  3.   

    你那count(jf_yesno)是数jf_yesno个数,还是jf_yesno合计值?
      

  4.   

    这个jf_yesno里有1,2,3,4种值.我要汇总1,2,3,4各个数的个数!
      

  5.   

    除了1.2.3.4外无其它值?有无NULL值?
      

  6.   

    select a.sgs_id,c.cla_name,d.cou_name,e.tea_name,
    sum(case when f.jd_select=0 
             then jf_grades
             else (case when jf_yesno is null 
                        then 0 
                        else 1 
                        end) 
             end)
    from 
    tb_judgefile a,
    tb_classcourse b,
    tb_class c,
    tb_course d,
    tb_teacher e,
    tb_judgedate f 
    where a.jt_tc_id=b.jt_tc_id
    and b.cla_id=c.cla_id
    and b.cou_id=d.cou_id
    and b.tea_id=e.tea_id
    group by a.sgs_id,c.cla_name,d.cou_name,e.tea_name
      

  7.   

    没有NULL,唉,搞不懂.为什么就只要这样连接一下就可以了哦!
      

  8.   

    呵呵,真的吗?不过,我对老大的理解呢是:技术好,就是老大group by a.sgs_id,c.cla_name,d.cou_name,e.tea_name这句的意思是先按sgs_id分组,再按cla_name,cou_name,tea_name分组?
    我说照这样分组下去的话就没有组可言了耶!因为各是一条记录!
      

  9.   

    1.如果:d.cou_name,e.tea_name要:
    select a.sgs_id,max(c.cla_name),max(d.cou_name),e.tea_name,
    sum(case when f.jd_select=0 
             then jf_grades
             else (case when jf_yesno is null 
                        then 0 
                        else 1 
                        end) 
             end)
    from 
    tb_judgefile a,
    tb_classcourse b,
    tb_class c,
    tb_course d,
    tb_teacher e,
    tb_judgedate f 
    where a.jt_tc_id=b.jt_tc_id
    and b.cla_id=c.cla_id
    and b.cou_id=d.cou_id
    and b.tea_id=e.tea_id
    group by a.sgs_id,c.cla_name1.如果:d.cou_name,e.tea_name不要:
    select a.sgs_id,c.cla_name,
    sum(case when f.jd_select=0 
             then jf_grades
             else (case when jf_yesno is null 
                        then 0 
                        else 1 
                        end) 
             end)
    from 
    tb_judgefile a,
    tb_classcourse b,
    tb_class c,
    tb_judgedate f 
    where a.jt_tc_id=b.jt_tc_id
    and b.cla_id=c.cla_id
    group by a.sgs_id,c.cla_name
      

  10.   

    真的非常谢谢j9988的帮忙!为什么.cou_name,e.tea_name要,就要用MAX(cou_name),max(tea_name)
    呀?
      

  11.   

    按你题意:tb_course tb_teacher 两表好象可以不要啊
    如果要名称,分组NAME只有取最大或最小的了
      

  12.   

    不行,这个tb_course,tb_teacher肯定是要的.我这只是简化问题.就只分别
    取他们的名字就没有取了!呵呵,高手你是从哪方面看出可以不要呢?那分组我看了一下帮助.用了group by 就只可以用聚簇函数了!
      

  13.   

    那你就要了,可能取其它值吧,如果取非GROUP BY的值一定要用聚合函数