我想用另一个对象替换嵌套对象。
这是最简单的表达方式吗?
LIMIT 1
答案 0 :(得分:2)
您可以使用WITH SampleInput AS (
SELECT 1 AS id, 'apple' AS name UNION ALL
SELECT 1, 'banana' UNION ALL
SELECT 2, 'carrot' UNION ALL
SELECT 3, 'lemon' UNION ALL
SELECT 3, 'orange'
)
SELECT
id,
ARRAY_AGG(name ORDER BY name DESC LIMIT 1)[OFFSET(0)] AS last_record_of_name
FROM SampleInput
GROUP BY id;
+----+---------------------+
| id | last_record_of_name |
+----+---------------------+
| 1 | banana |
| 2 | carrot |
| 3 | orange |
+----+---------------------+
:https://www.rethinkdb.com/api/javascript/literal
r.expr({ foo: {bar: 1}, eck: true })
.merge({ foo: null }, { foo: {zim: 1} })
// Expected output: { foo: {zim: 1}, eck: true }