表1
部门ID
部门名表2
指标ID
指标名表3
部门ID
指标ID
时间(按月数来)
分数现在有3个部门,部门1,部门2,部门3
有一个指标,叫指标N
在表3里,一个部门可以对同一个指标按不同时间打多次分
要搜索出一个时间段里,每个部门的这个指标的所有分数求合,并且排序

解决方案 »

  1.   

    setect t1.部门名,t2.指标名,t3.分数 from 表1 as t1,表2 as t2,表3 as t3, where t1.部门ID=t3.部门ID and 
    t2.指标ID=t3.指标ID and t3.时间>'起始时间' and 时间<'结束时间'  order by t3.分数 asc
      

  2.   

    分数求和这个没看到这样改一下就是了setect t1.部门名,t2.指标名,sum(t3.分数) as 分数合 from 表1 as t1,表2 as t2,表3 as t3, where t1.部门ID=t3.部门ID and 
    t2.指标ID=t3.指标ID and t3.时间>'起始时间' and 时间<'结束时间'  group by t3.部门ID
    ,t1.部门名,t2.指标名当然时间搜索段也可以加到group by 子句里 用datepart(表达示,时间)