日期:2014-05-17 浏览次数:21243 次
A表
f_line f_produce f_date f_qty --大概1W条
1005 KX-AAA-R1 2014-01-03 80
1004 KX-BBB-R1 2014-01-05 90
B表
f_line f_produce f_date f_qty --大概1W条
1005 KX-AAA-R1 2014-01-03 80
1004 KX-CCC-R1 2014-01-05 90
A表和B表其他字段就不打出来了,主要需要数据的字段
--现在的sql
select a.f_linename,a.f_producemodel,left(a.f_date,7),sum(a.f_qty),b.f_linename,b.f_producemodel,left(b.f_date,7),sum(b.f_qty) from a
left join b on a.f_linename = b.f_linename and a.f_producemodel = b.f_producemodel
and left(a.f_date,7) = left(b.f_date,7) where a.f_batch = 28 and b.f_batch = 28
group by a.f_linename,a.f_producemodel,left(a.f_date,7),
b.f_linename,b.f_producemodel,left(b.f_date,7)
select a.f_linename,a.f_producemodel,left(a.f_date,7),
sum(a.f_qty),b.f_linename,b.f_producemodel,left(b.f_date,7),sum(b.f_qty)
from a
left hash join b on a.f_linename = b.f_linename and a.f_producemodel = b.f_producemodel
and left(a.f_date,7) = left(b.f_date,7) where a.f_batch = 28 and b.f_batch = 28
group by a.f_linename,a.f_producemodel,left(a.f_date,7),
b.f_linename,b.f_producemodel,left(b.f_date,7)