我有 3 个表,我需要选择显示平均交易银行。我该怎么做,我需要进行查询?
1.存款
`ID_Deposit DepositBy . Money . Slip . Status . DateTime `
1 Harmonic 200 . Slip.jpg Success 10/10/2019
2 Invicta 200 . Slip1.jpg Success 11/10/2019
2.传输
`Id_Tranfer Sent . Money . Received . DateTime . Status `
1 Harmonic 200 . Invicta 12/10/2019 Success
3.提现
`Id_Withdraw WithdrawBy . Money . Status . DateTime . `
1 Harmonic 200 . Success 13/10/2019
试试这个。希望这就是你要找的。 您不能合并不同的列,这就是为什么我将别名更改为fakename
以使联合工作的原因。
select a.* from(
Select deposit_by as fakename,money,dtime from Deposit
Union all
Select sent as fakename,money,dtime from Transfer
Union all
Select withdrawby as fakename,money,dtime from Withdraw
) as a order by a.dtime desc
样品小提琴
SELECT * FROM (
SELECT ID_Deposit IdentityID, 'Deposit' TypeTransaction,DepositBy Person,Money,Slip,NULL Received,Status,DateTime FROM Deposit
UNION
SELECT Id_Tranfer IdentityID, 'Tranfer' TypeTransaction,Sent Person,Money,NULL Slip,Received,Status,DateTime FROM Tranfer
UNION
SELECT Id_Withdraw IdentityID, 'Withdraw' TypeTransaction,WithdrawBy Person,Money,NULL Slip,NULL Received,Status,DateTime FROM Withdraw
) Z
ORDER BY DateTime ASC