急求:关于表的连接
现有1个表:借码 借钱 贷码 贷钱
101 10 102 10
101 50 103 50
105 20 101 20
想得到这样的结果:(存入另一个表中)
代码 借钱 贷钱
101 10 0
101 50 0
101 0 20
102 0 10
103 0 50
105 20 0
请高手帮看一下!!!!谢了!!!
------解决方案--------------------select *
from (
SELECT 借码 as 代码, 借钱, 0 as 贷钱
FROM 表名
union all
SELECT 贷码 as 代码, 0, 贷钱
FROM 表名
) T
order by 代码
------解决方案--------------------select *
from (
SELECT 借码 as 代码, 借钱, 0 as 贷钱 FROM tt
union all
SELECT 贷码 as 代码, 0, 贷钱 FROM tt
) order by 代码