表A:
    出厂编号    名称     装配日期
    1111        BMW760      2003-12-10
    2222        BMWX5       2003-12-15
    
表B:
   出厂编号     操作内容    操作者    操作工时
   1111          油漆        张三      5
   1111          绑金        李四      3
   2222          油漆        张三      4
   2222          绑金        李四      7
  我现在统计操作者的工时的SQL语句如下:,
select '姓名'=操作者,'总工时'=sum( 操作工时) from 表B group by 操作者
结果如下(已经达到我的目的)
 姓名  总工时
 张三    9
 李四    10我现在想给个条件,我要统计时间在2003-12-11之后面的工时
这个带where的 SQL语句好象不好写,望大家帮忙?
这里先谢了!!

解决方案 »

  1.   

    where 出厂编号 in (select 出厂编号 from A where 装配日期>2003-12-11)
      

  2.   

    select '姓名'=操作者,'总工时'=sum( 操作工时) from 表A 表B group by 操作者  
    where 表A.出厂编号=表B.出厂编号 and 装配日期>2003-12-11
      

  3.   

    select 表B.操作者,sum(表B.操作工时) from 表A,表B   
     where to_char(表A.装配日期,'yyyymmdd')>'20031211' and  表A.出厂编号=表B.出厂编号 
       group by 表B.操作者
      

  4.   

    select '姓名'=操作者,'总工时'=sum( 操作工时) 
    from 表B 
    where exists(select * 
                 from 表A 
                 where (表A.出厂编号=表B.出厂编号)and(表B.装配日期>'2003-12-11'))
    group by 操作者
    用EXISTS比IN效率高