gpt4 book ai didi

php - 选择仅具有一个值的优先级数组

转载 作者:行者123 更新时间:2023-11-29 13:25:12 24 4
gpt4 key购买 nike

我有视频表:

如何获取对请求类别定义较好的记录并忽略相似。

SELECT [...] WHERE category IN(1,2,3,4);

预期结果:

最佳答案

关键是找到具有最小基数的匹配类别:

with given_data(cat) as (
select * from unnest (array[1,2,3,4])
)
select distinct on(cat) *
from urls
cross join given_data
where cat = any(category)
order by cat, cardinality(category);

id | url | category | cat
----+----------+-----------+-----
1 | example1 | {1,2,3,4} | 1
2 | example2 | {2} | 2
3 | example3 | {3} | 3
4 | example4 | {4} | 4
(4 rows)

关于php - 选择仅具有一个值的优先级数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com