gpt4 book ai didi

mysql - WHERE IN - 必须满足所有参数

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

我正在执行“Where In”查询。

这是我的查询:

select * from `xh_user` 
where (select count(*)
from `xh_roles`
inner join `xh_role_user` on `xh_roles`.`id` = `xh_role_user`.`role_id`
where `xh_role_user`.`user_id` = `xh_user`.`id`
and `title` in (?, ?)) >= 1
and `id` = ? limit 1'

我正在搜索标题符合我的参数的行。

如果满足其中一个参数,则行返回。

如何才能满足所有参数?

最佳答案

假设您有两个参数:

select *
from `xh_user`
where (select count(distinct title)
from `xh_roles` inner join
`xh_role_user`
on `xh_roles`.`id` = `xh_role_user`.`role_id`
where `xh_role_user`.`user_id` = `xh_user`.`id` and
`title` in (?, ?)
) = 2 and
`id` = ?
limit 1;

关于mysql - WHERE IN - 必须满足所有参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25362899/

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