如何使用SQL::AbstractWHERE
为该查询生成子句:
SELECT COUNT(*) FROM table WHERE id = 111 AND NOT FIND_IN_SET(type, '1,2,3,4') AND status = 'pending';
包含类似条件的正确方法是WHERE FIND_IN_SET(type, '1,2,3,4')
什么?
如何使用SQL::AbstractWHERE
为该查询生成子句:
SELECT COUNT(*) FROM table WHERE id = 111 AND NOT FIND_IN_SET(type, '1,2,3,4') AND status = 'pending';
包含类似条件的正确方法是WHERE FIND_IN_SET(type, '1,2,3,4')
什么?
请参阅not_bool一元运算符选项:
use SQL::Abstract;
my $sql = SQL::Abstract->new;
my $where = {
id => 111,
status => 'pending',
-not_bool => "FIND_IN_SET(type, '1,2,3,4')",
};
my ($query, @bind) = $sql->select(
'table',
'count(*)',
$where,
);
$query
看起来是这样的:
SELECT count(*) FROM table WHERE ( ( (NOT FIND_IN_SET(type, '1,2,3,4'))
AND id = ? AND status = ? ) )
此代码生成WHERE
子句:
my $sql = SQL::Abstract->new;
my %where = (
id => 111,
-nest => \"NOT FIND_IN_SET(type, '1,2,3,4')",
status => 'pending',
);
my ($stmt, @bind) = $sql->where(\%where, \@order);
FIND_IN_SET 不是标准 SQL,因此 SQL::Abstract 不支持它。但是,您可以将任何文字 SQL放入 SQL::Abstract 查询中。我希望您的解决方案位于这条路线上。