我对SQL有疑问。
我有两张桌子。
Buy and Sell
在这些表中,数据有些相同。
ID,数量,总和,时间戳
如何打印按时间戳排序的两个表格。 所以它看起来像这样
Buy | 1 | 5 | 100 | 14:14:14 |
Buy | 2 | 22 | 50 | 14:14:20 |
Sell | 1 | 1 | 20 | 14:15:01 |
等等..我只需按时间戳排序
答案 0 :(得分:3)
使用UNION
SELECT 'Buy' as [Type], b.* FROM BUY as b
UNION ALL
SELECT 'Sell' as [Type], s.* FROM SELL as s
ORDER BY Timestamp
答案 1 :(得分:1)
你应该可以这样做:
SELECT ID, Quantity, Sum, TimeStamp
FROM Buy
UNION ALL
SELECT ID, Quantity, Sum, TimeStamp
FROM Sell
ORDER BY TimeStamp