Perl DBIx :: Class :: ResultSet不同的值

时间:2017-01-03 16:58:21

标签: mysql perl dbix-class

您好我想使用DBix :: Class从数据库中获取唯一(不同)值,但无法使用我当前的搜索方法找到该方法:

my $rs = $schema->resultset('DiscreteCalendar')->search(
        {
            holidaytype => 'W',
            branchcode  => $branchcode,
        },
        {
            select => [{ DAYOFWEEK => 'date' }],
            as     => [qw/ weekday /],
            where       => \['date between ? and ?',$today, $endDate ],

        }
    );

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您应该只需将第二个哈希中的distinct => 1添加到search函数中,例如:

my $rs = $schema->resultset('DiscreteCalendar')->search(
    {
        holidaytype => 'W',
        branchcode  => $branchcode,
    },
    {
        distinct => 1,
        select => [{ DAYOFWEEK => 'date' }],
        as     => [qw/ weekday /],
        where       => \['date between ? and ?',$today, $endDate ],

    }
);