[Catalyst] Sort - ORDER BY

Bill Moseley moseley at hank.org
Tue Nov 8 22:03:08 CET 2005


On Tue, Nov 08, 2005 at 12:43:43PM -0800, Will Smith wrote:
> and if i am not too greedy, do you mind to give me some hint on
> return a "top 10 records" . These could be doe easily with sql
> statement. But I am develop an app using pure catalyst, so it's a
> bit ticky with the syntax.

You can still use sql.


DB::Person->columns( TEMP => 'reg_count' );

DB::Person->set_sql( 'top_ten', <<'');
    SELECT      person.id, person.first_name, COUNT(registration.id) as reg_count
    FROM        person, registration
    WHERE       registration.person = person.id
    GROUP BY    person.id, person.first_name
    ORDER BY    reg_count DESC
    LIMIT       10


printf("%5s | %10s | %10s\n", $_->reg_count, $_->first_name, $_->id )
    for DB::Person->search_top_ten;


$ perl test.pl
   81 | Marilyn    |        161
   53 | Joe        |       5226
   51 | Sean       |        713
   40 | Deborah    |        158
   39 | Bonnie     |        631
   37 | Michael    |       4865
   36 | Virginia   |         99
   36 | Tom        |       5229
   34 | Sabah      |       1604
   31 | Rubi       |        399


-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list