获取列的最大值并将它们与另一个 table

Getting max values for columns and join them with another table

我是 SQL 查询的新手。我计划在 HANA Express 中加入 2 tables 并获得一个 table 的两列的最大值并将其与另一个 table 加入。这是场景:

Table A
+-----+----------------+
| Key |     Value      |
+-----+----------------+
|   1 | Value is 1     |
|   2 | Value is 2     |
|   3 | Value is 3     |
+-----+----------------+

Table B
+-----+----------------------------+------+
| Seq |         Timestamp          | Key  |
+-----+----------------------------+------+
| 500 | Feb 3, 2017 6:35:59.742 PM |    1 |
| 501 | Feb 3, 2017 6:35:59.742 PM |    2 |
| 502 | Feb 3, 2017 6:36:05.758 PM |    2 |
| 503 | Feb 3, 2017 6:36:05.758 PM |    4 |
| 504 | Feb 3, 2017 6:36:05.758 PM |    3 |
| 505 | Feb 3, 2017 6:36:09.766 PM |    5 |
+-----+----------------------------+------+

output table
+-----+------------+--------+----------------------------+--------------------------------+
| Key |   Value    | MaxSeq |      LatestTimeStamp       |          ExecutionTime          |
+-----+------------+--------+----------------------------+--------------------------------+
|   1 | Value is 1 |    505 | Feb 3, 2017 6:36:09.766 PM | (execution time of this query) |
|   2 | Value is 2 |    505 | Feb 3, 2017 6:36:09.766 PM | (execution time of this query) |
|   3 | Value is 3 |    505 | Feb 3, 2017 6:36:09.766 PM | (execution time of this query) |
+-----+------------+--------+----------------------------+--------------------------------+

所以这里的 MaxSeq 将是 table B 中 Seq 列的最大值,而 LatestTimeStamp 是 table B 的时间戳列的最新时间戳,并且它们在连接中都是常量table。根据 HANA 中的 Current_Timestamp 函数计算的执行时间。有可能吗?

试试这个:

select a.Key, a.Value, 
(select max(Seq) from TableB) MaxSeq, 

(select max(Timestamp) from TableB) c LatestTimestamp, ???执行时间处理时间 来自表 A

更好:

select a.Key, a.Value, b.MaxSeq, b.LatestTimestamp , 
Current_Timestamp - b.LatestTimestamp Executiontime
from TableA, 
 (select max(Seq) MaxSeq,  max(Timestamp) LatestTimestamp from TableB) b