MS Access。我正在查询一个表,该表显示了许多客户端和版本的client_name,release_name,release_date。我正在尝试编写一个查询,为一个客户端返回以下数据:client_name,release_name,from_release_date,to_release_date。在这种情况下,from_release_date是基础表的原始release_date,但查询to_release_date中的新字段是安装下一个版本的前一天。例如:
+-------------+-----------+-------------------+-------------------+
| client_name | release | from_release_date | to_release date |
+-------------+-----------+-------------------+-------------------+
| client A | release 1 | 01/01/2017 | 01/02/2017 |
| client A | release 2 | 02/02/2017 | 02/03/2017 |
| client A | release 3 | 03/03/2017 | |
+-------------+-----------+-------------------+-------------------+
如何创建此'to_release_date'字段?
答案 0 :(得分:0)
使用子查询:
Select
client_name,
release_name,
release_date As from_release_date,
(Select Top 1
DateAdd("d", -1, T.release_date)
From
YourTable As T
Where
T.client_name = YourTable.client_name
And
T.release_date > YourTable.release_date
Order By
T.release_date Desc) As to_release_date
From
YourTable