gpt4 book ai didi

php - 如果条件在多行中匹配,则从映射表中获取数据

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

product_id   property_id

1 2
1 5
2 2
3 5

我有一个如上的映射表。如果 product_id in (2,5),我只想获得 id =1 的产品。即,如果表同时包含 2,5 我想获取数据,而不是如果它包含 property_id 只有 2 或 5

select group_concat(distinct product_id) product_ids from table where property_id in (2,5)

更新:property_id in 可以是 property_id in(2,5,....)。我从表单中得到的输出为 2,5,.... 等等。它不仅仅是针对单个案例。如果 property_id 中的条件与整个系列匹配,我只想要输出。

最佳答案

这是怎么做到的

select
product_id from
table_name
where property_id in (2,5)
group by product_id
having count(*) = 2

您只需将 having count(*) = 2 更改为 IN() 中的项目数,现在是 2,如果您正在查看 3 property id 那么它将是 3 等等。

关于php - 如果条件在多行中匹配,则从映射表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23949893/

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