【发布时间】:2021-11-18 02:45:43
【问题描述】:
我有下表:
Id | Plate | RecordedAt
每个不同的车牌可以有N条记录。
我正在为以下查询而苦苦挣扎:
SELECT TOP 1 *
FROM table
WHERE table.Plate IN ('plate1', 'plate2', 'plate3')
ORDER BY c.Recordedat DESC
问题是这个查询只返回 1 条记录,最后一个 Recordedat 项。
我需要列表中每个项目的最后一个Recordedat。
有没有办法只用一个查询来实现这一点?
例如以下记录:
Id | Plate | RecordedAt
1 | Plate1 | 2021/09/26 6:53:06
3 | Plate2 | 2021/09/25 7:45:10
4 | Plate3 | 2021/09/23 02:10:42
5 | Plate1 | 2021/09/25 02:40:02
6 | Plate2 | 2021/09/26 15:14:02
7 | Plate1 | 2021/09/26 01:02:04
8 | Plate3 | 2021/09/26 16:02:20
9 | Plate1 | 2021/09/24 05:02:20
10 | Plate2 | 2021/09/24 04:03:02
我需要返回:
[
{
"Plate1":"2021/09/26 15:14:02"
},
{
"Plate2":"2021/09/26 15:14:02"
},
{
"Plate3":"2021/09/26 16:02:20"
},
]
【问题讨论】:
-
您能否提供一些您尝试查询的示例数据,只是一些文档。
-
我已经编辑了帖子以添加一些记录和预期结果
标签: azure azure-cosmosdb