`
dchaoxiong
  • 浏览: 180803 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

sql精华

SQL 
阅读更多

把海量数据整理到一张临时表(t表和p表的数据都是海量的)

insert into testresult(account, cardno, point_value)
select p.ACCOUNT, t.CARDNO, sum(p.POINT_VALUE) from T_TRANSHISTORY2005 t, POINT_HISTORY_LINE p
where t.SYSTEMTRACE = p.ECP_TRACE
    and t.CARDNO is not null
group by p.ACCOUNT, t.CARDNO

 

 

联合多张表的总记录作为临时表,并对这个临时表做分组统计处理

select cardno,account,sum(point_value) from(
    select cardno,account,point_value
    from(
        select *  
        from TESTRESULT_2006  
        union all 
        select *
        from TESTRESULT_2007
    ) tem
) group by cardno,account
;

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics