要求今天1时(20060108),统计昨天(20060107)的TB_User表的业绩数据

解决方案 »

  1.   

    -- 楼主的表中的字段和结果字段对应不太清晰.-- 大致的处理代码如下:
    select a.unionname,b.userhandup,
        tjmmobile=sum(case when b.usertype='移动' then 1 else 0 end),
        tjmunicom=sum(case when b.usertype='联通' then 1 else 0 end),
        tjmoney=sum(b.usermoney)
    from tb_union a
        left join tb_user b 
          on a.unionid=b.userunionid
    group by a.unionname,b.userhandup
      

  2.   

    这个问题昨天好像有人答过了,楼主是想要insert到表TB_TJM,其实已经告诉他在sql语句前加个insert TB_TJM 就行,不知为何又提同一问题??借老大的语句用一下。insert TB_TJM 
    select TjmName=a.unionname,
           TjmTime=b.userhandup,
        tjmmobile=sum(case when b.usertype='移动' then 1 else 0 end),
        tjmunicom=sum(case when b.usertype='联通' then 1 else 0 end),
        tjmoney=sum(b.usermoney)
    from tb_union a
        left join tb_user b 
          on a.unionid=b.userunionid
    group by a.unionname,b.userhandup