用内外连接都实现不了的语句 大家帮我看看
现在有俩个表 grn 和 ma
grn
AID AORDER ANO AGRN qty
1 pp-1 it1 H01 20
2 pp-1 it1 H01 19
3 pp-1 it1 H01 20
4 PP-1 it2 HO1 23
ma
bid border bno bwh bloc
10001 pp-1 it1 a 101
10002 pp-1 it1 a 102
10003 pp-1 it1 a 103
10004 pp-1 it2 a 109
想要的结果是
agrn aorder ano qty bwh bloc
HO1 PP-1 IT1 20 A 101
HO1 PP-1 IT1 19 A 102
HO1 PP-1 IT1 20 A 103
HO1 PP-1 IT2 23 A 109
请问怎样实现????
------解决方案----------------------环境
create table grn
(
aid int,
aorder varchar(4),
ano varchar(4),
agrn varchar(4),
qty int
)
create table ma
(
bid int,
border varchar(4),
bno varchar(4),
bwh varchar(4),
bloc int
)
insert into grn select 1, 'pp-1 ', 'it1 ', 'H01 ', 20
insert into grn select 2, 'pp-1 ', 'it1 ', 'H01 ', 19
insert into grn select 3, 'pp-1 ', 'it1 ', 'H01 ', 20
insert into grn select 4, 'PP-1 ', 'it2 ', 'HO1 ', 23
insert into ma select '10001 ', 'pp-1 ', 'it1 ', 'a ', 101
insert into ma select '10002 ', 'pp-1 ', 'it1 ', 'a ', 102
insert into ma select '10003 ', 'pp-1 ', 'it1 ', 'a ', 103
insert into ma select '10004 ', 'pp-1 ', 'it2 ', 'a ', 109
--语句
select t1.agrn,t1.aorder,t1.ano,t1.qty,t2.bwh,t2.bloc
from
(select
newaid = (select count(1) from grn
where aid <= a.aid and AORDER = a.aorder and ANO = a.ano),
AORDER,ANO,AGRN,qty
from grn a
) t1,
(select
newbid = (select count(1) from ma
where bid <= b.bid and border = b.border and bno = b.bno),
border,bno,bwh,bloc
from ma b
) t2
where t1.newaid = t2.newbid and t1.aorder =