我正在使用SQL Server Compact Edition 4.0,下面有2个名为借记和贷记的表。
tbl_debit
invoice | dealer | price| purchasedate
=========================================
001 | AAA | 1000 | 2/9/2016 8:46:38 PM
002 | AAA | 1500 | 2/20/2016 8:46:38 PM
tbl_credit
dealer | settlement| purchasedate
=========================================
AAA | 800 | 2/12/2016 8:46:38 PM
AAA | 400 | 2/22/2016 8:46:38 PM
我想创建一个应该包含4列的单个表..
Invoice, Dealer, Amount, date
金额应包括来自settlement
的{{1}}和来自tbl_credit
的{{1}},并且需要按日期排序。
如果有人能帮助我,我真的很感激。
答案 0 :(得分:1)
这是一个基于提供给我们的有限信息在逻辑上解决问题的脚本:
SELECT A.invoice, A.dealer, A.amount, A.purchasedate
FROM (SELECT A.invoice, A.dealer, A.price [amount], A.purchasedate
WHERE tbl_debit A
UNION
SELECT ' ', B.dealer, B.settlement, B.purchasedate
FROM tbl_credit B) A
ORDER BY 4