分享到:
发表于 2009-06-10 15:57:51 楼主 | |
表1 0002|42020005|张三|925.00 0003|42020005|张三|925.00 0004|42020006|李四|125.00 0005|42020007|王五|225.00 表2 10021|张三|925.00 10022|张三|925.00 10023|张三|925.00 10026|李四|125.00 10027|王五|225.00 10028|王五|225.00 10029|赵六|125.00 连接为 10021|张三|925.00|4202005|0002 10022|张三|925.00|4202005|0003 10026|李四|125.00|4202006|0004 10027|王五|225.00|4202007|0005 就是当姓名一样金额一样时,只能连接同表1笔数相同的数据,如何选择连接了 |
|
楼主热贴 |
发表于 2009-06-10 15:58:21 1楼 | |
create table #a (id varchar(10),ord_id varchar(10),name nvarchar(20),amount dec(10,2)) create table #b (id varchar(10),name nvarchar(20),amount dec(10,2)) insert into #a select \'0002\',\'42020005\',N\'张三\',925.00 union all select \'0003\',\'42020005\',N\'张三\',925.00 union all select \'0004\',\'42020006\',N\'李四\',125.00 union all select \'0005\',\'42020007\',N\'王五\',225.00 insert into #b select \'10021\',N\'张三\',925.00 union all select \'10022\',N\'张三\',925.00 union all select \'10023\',N\'张三\',925.00 union all select \'10026\',N\'李四\',125.00 union all select \'10027\',N\'王五\',225.00 union all select \'10028\',N\'王五\',225.00 union all select \'10029\',N\'赵六\',125.00 select b.id as b_id,a.name,a.amount,a.ord_id,a.id a_id from (select row_number() over( order by name,amount) rowid,* from #a) a inner join (select row_number() over( order by name,amount) rowid,* from #b) b on a.rowid=b.rowid |
|
针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员 、 查看帮助 或 给我提意见