gpt4 book ai didi

php - 检查表mysql查询中可用的所有id值列表

转载 作者:行者123 更新时间:2023-11-30 23:07:17 24 4
gpt4 key购买 nike

表格

id | catid | productid | 

1 3 100

2 244 110

3 400 300

你好,这是我的问题,

select catid from table where catid NOT IN ('3','244','5')

我有一张像上面那样的 table ,

1- 我需要什么,我必须检查一些 catid 值列表,如果所有列表 catid 都可用,则该表将返回"is"或一些“行”。

2- 否则将返回“否”所有列表 catid 不可用?

我试过了,但没用?

这不是我预期结果的正确结果吗?

SELECT catid , IF(catid IS NOT NULL , "Yes", "No") FROM table where catid IN ('3','244','5');

我需要的是,猫 ID 列表是“('3','244','5')”,如果一旦缺少值,表格将返回“否”,表格应该可用

谢谢你的帮助?

最佳答案

解决这个问题的一种方法是使用左外连接和聚合:

select (case when count(distinct t.catid) = 3 then 'Yes'
else concat('No, missing ',
group_concat(case when t.catid is null then vals.val end)
)
end)
from (select '3' as val union all '244' union all '5'
) vals left outer join
t
on t.catid = vals.val;

列表本身作为一组行进入第一个子查询,每行一个值。

关于php - 检查表mysql查询中可用的所有id值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21308332/

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