cosmos db select with where子句with max date

z18hc3ub  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(463)

我想选择最长日期的项目。
我有 select :

select d.MaxDate from (select max(c.ChangedDateTime) MaxDate FROM c WHERE AND c.IsLatest = true) d

结果是:

[
    {
        "MaxDate": "2020-07-16 12:23:57"
    }
]

现在我要选择一行的最大日期:

select * FROM c WHERE IsLatest = true 
WHERE c.ChangedDateTime = (select d.MaxDate from (select max(c.ChangedDateTime) MaxDate 
FROM c WHERE AND c.IsLatest = true) d)

结果为空,应返回一行日期 2020-07-16 12:23:57 当我这样选择的时候:

select * from c where c.IsLatest = true AND c.ChangedDateTime = '2020-07-16 12:23:57'

它只返回我想要的一行,所以我认为subselect有问题,因为它返回带有object的数组 [{"MaxDate": "2020-07-16 12:23:57"}]

lkaoscv7

lkaoscv71#

排序后只选一行怎么样?

SELECT *
FROM c
WHERE IsLatest = true 
ORDER BY c.ChangedDateTime
OFFSET 0 LIMIT 1;

相关问题