English 中文(简体)
DBIx:Class : Resultset Order_by based on existence of a Value in the list
原标题:DBIx::Class : Resultset order_by based upon existence of a value in the list

我正在使用德国统计局:地图集,我已经获得一个结果。 我愿重新排序。 我要对照一个固定价值清单(伦敦”、“纽约”“东京”)检查一个特定的“核心”栏。 如果城市出现在价值观清单中,我想把这一结果推向上层。 如果找不到城市,我就希望把这一结果推向下院。

最佳回答

rel=“nofollow”>ORDER BYpr可能是你重新研究的。

例如,在此表格中:

mysql> select * from test;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | London    |
|  2 | Paris     |
|  3 | Tokio     |
|  4 | Rome      |
|  5 | Amsterdam |
+----+-----------+

特别命令:

mysql> select * from test order by name =  London  desc, 
                                   name =  Paris   desc, 
                                   name =  Amsterdam  desc;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | London    |
|  2 | Paris     |
|  5 | Amsterdam |
|  3 | Tokio     |
|  4 | Rome      |
+----+-----------+

将此转化为结果 一套方法:

$schema->resultset( Test )->search(
    {},
    {order_by => {-desc => q[name in ( London ,  New York ,  Tokyo )] }}
);
问题回答

类似:

#!/usr/bin/env perl
use strict;
use warnings;
my $what = shift or die;
my @ary  = qw(alpha beta gamma);
unshift(@ary,$what) unless ( grep(/$what/,@ary) );
print "@ary
";
1;

如下:

./myscript omega




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签