[英]SQL return max in unnest
I have the following query:我有以下查询:
SELECT
table_a.col1,
table_a.col2,
array.col1
FROM
table_a
LEFT JOIN UNNEST(table_a.array) AS array
What should I do if I only want the query to return one array.col1
per row in table_a
(let's say I want only the max
value for each case)?如果我只希望查询在
table_a
中每行返回一个array.col1
应该怎么办(假设我只想要每种情况的max
)?
You can use a subquery:您可以使用子查询:
select a.*,
(select max(el)
from unnest(a.array) el
) as max_el
from table_a a;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.