问题
Sample data :
{age: 20, ts: '00:00'},
{age: 20, ts: '00:01'},
{age: 30, ts: '00:00'},
{age: 30, ts: '00:01'},
{age: 40, ts: '00:00'},
{age: 40, ts: '00:01'},
{age: 40, ts: '00:02'}
Expected output:
[{age: 20, ts: '00:01'},
{age: 30, ts: '00:01'},
{age: 40, ts: '00:02'}]
Tried
SELECT * FROM c where c.age in (20, 30, 40) order by c.ts desc
But the result selected all data.
回答1:
Please try something like the following:
SELECT max(c.ts) as ts, c.age FROM c where c.age in (20, 30, 40)
Group By c.age
This gives the following output:
[
{
"ts": "00:02",
"age": 40
},
{
"ts": "00:01",
"age": 30
},
{
"ts": "00:01",
"age": 20
}
]
来源:https://stackoverflow.com/questions/62527835/query-last-data-of-different-documents-in-azure-cosmos-db-sql