select type,point from a  得到 类型 和扣分
得到三行数据(只有):病假 分值1,事假 分值2 ,迟到 分值3 类型是确定的只有3种但是分值是人工维护的
select 编号,病假,事假 ,迟到 from b 
得到N 行数据如:1   1  1  1
               2   1  0  1
其中得到病假,事假 ,迟到的意思是病假次数、事假次数、迟到次数要求: 得到 select 编号 , 病假次数*分值1,事假次数*分值2,迟到次数*分值3

解决方案 »

  1.   


    select 编号, Sum(case when 类型='病假' then 1 else 0 end)*分值1 A
               , Sum(case when 类型='事假' then 1 else 0 end)*分值2 B
               , Sum(case when 类型='迟到' then 1 else 0 end)*分值3 C
    from table 
    group by 编号
      

  2.   

    select a.编号,a.病假*(select point from a where type='病假'),
                  a.事假*(select point from a where type='事假'),
                  a.迟到*(select point from a where type='迟到)
    from b
      

  3.   

    select b.编号,b.病假*(select point from a where type='病假'),
                  b.事假*(select point from a where type='事假'),
                  b.迟到*(select point from a where type='迟到)
    from b这些应该是B表吧