gpt4 book ai didi

mysql - Rose DB 子选择(嵌套查询)

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

我正在尝试运行一个查询,其中有一个子选择。我已经设置了 Manager 方法,一切正常。唯一的问题是我不知道如何继续这个查询:

SELECT * FROM tableA WHERE 
name = 'Me' AND
class='Tester' AND
( ( Department IN ( SELECT Department FROM
tableB WHERE
leader = 'Joe')
OR
Leader in ('','all') )
);

重要的是要记住 tableA 和 tableB 是 2 个不同的表。截至目前我已经达到了这个查询:

my @leader = ('','all');

DB::tableA::Manager->get_tableA ( with_object => ['tableB'] ,
query => [ name => 'Me',
class => 'Tester',
OR => [
leader => \@leader,
Department => [*** this is
where i have to make the sub select.
Dont know how though **** ]
]
],
debug => 1);

请帮忙,以便我可以将该子查询添加到此主查询

提前致谢

最佳答案

您可以使用clauses函数在查询的WHERE部分中包含任意子句。

它看起来像这样。

DB::tableA::Manager->get_tableA ( with_object => ['tableB'] , 
query => [
name => 'Me',
class => 'Tester',
],
clauses => ["( Department IN ( SELECT Department FROM tableB WHERE leader = 'Joe' ) OR Leader in ('','all') )"
);

CPAN: Rose::DB::Object::QueryBuilder, Functions

关于mysql - Rose DB 子选择(嵌套查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269054/

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