gpt4 book ai didi

mysql - 将子查询结果传递到查询的 IN 子句中

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

我想将子查询返回的结果使用到mysql中另一个查询的IN子句中,我想做一些类似于oracle数据库中的BULK COLLECT的操作,但我想mysql中没有类似的东西

例如:

set @features := (select group_concat(apf.featureid ) from 
applicationpackagefeature apf ,
feature f,
applicationpackage ap,
applicationpackageapplication apa,
application a
where f.id = apf.featureid
and apf.applicationPackageId = ap.id
and apa.applicationPackageId = ap.id
and apa.applicationId = a.id
and a.platform = 'b'
and a.version = 'a'
and a.name = 'c');

我想存储此查询返回的 id 并在三个 set set od delete 语句中使用它,尽管我已经使用了 group_concat 但它不起作用

delete from applicationpackagefeature where featureid in (
@features
)

最佳答案

您可以使用 Prepared Statements 来实现此目的在 MySQL 中:

SET @query = CONCAT('delete from applicationpackagefeature where featureid in (
',@features,')');

PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt;

关于mysql - 将子查询结果传递到查询的 IN 子句中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33605476/

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