高分求把三张表合成一张表SQL
现在有扣款表 退款表 充值表
扣款表 字段: id orderid account account_end atime
数据例子 1 123 100 200 2011-1-1 9:00
退款表 字段 id orderid account account_end atime
数据例子 1 123 100 300 2011-1-2 8:00
充值表 字段 id account account_end atime
数据例子 1 100 300 2011-1-3 7:00
合成的是收支明细表 字段有 id orderid account account account account_end atime
例子 1 123 100 200 2011-1-1 9:00
2 123 100 300 2011-1-2 8:00
3 100 300 2011-1-3 7:00
求大神指导 其实 就是做一个银行的收支明细表 把三张表合成一张表
[解决办法]
三个表得有点关系吧。毫无关系的三张表么?
给你个简单的例子:
select filed1 as orderid, filed2 as kaccount, filed3 as aacount from tableA
union
select filed4 as orderid, filed5 as kaccount, filed6 as aacount from tableB
union
select filed7 as orderid, filed8 as kaccount, filed9 as aacount from tableC
[解决办法]
应该描述三张表的何种关系??
[解决办法]
如果三张表的字段类型相同,可以是:
select id orderid account account_end atime from 扣款表
union
select id orderid account account_end atime from 退款表
union
select id orderid account account_end atime from 充值表
[解决办法]
select * into 收支明细表 from
(
select id orderid account account_end atime from 扣款表
union
select id orderid account account_end atime from 退款表
union
select id orderid=null account account_end atime from 充值表
) t