我已經完成了下面的查詢。我在c#網格視圖中使用這個。這個查詢一切正常。但正如你所看到的,有一張名爲「ocum」的表正在爲特定條件拉取數據。從兩個相同的結構化表中獲取mysql查詢
table "ocum" = has records before today .
table "otrans" = has only today's records .
- 兩個表結構是相同的。
- 我得到的數據完全來自「ocum」表的數據。
- 現在我想獲得今日的數據,即從otrans表。
簡而言之,今天是19-04-2017。所以ocum表包含所有記錄到18-04-2017和otrans表只包含19-04-2017記錄。在一天的時間關閉OTTR記錄被附加/添加到ocum表。
如何從單個語句中的兩個表中查詢數據。 這是我的查詢。
SELECT
`ocum`.`tdate`,
`ocum`.`damt`,
`ocum`.`camt`,
`ocum`.`narr`,
@Bal := @Bal + `ocum`.`camt` - `ocum`.`damt` AS `bal`
FROM `ocum`, (SELECT @Bal := 0) AS variableInit where `ocum`.`glcode` = "A03208" and `ocum`.`acno` = 40
ORDER BY `ocum`.`tdate` ASC
如果我理解正確,你可以試試'UNION',https://dev.mysql.com/doc/refman/5.7/en/union.html –