[Dbix-class] Problem with getting a grouped count
Touya
dong.yi at adways.net
Wed Mar 22 03:30:09 CET 2006
hi,Matija Grabnar :
I have met the same problem with you when I use DBIC to order by a column which doesn't exist.As Mr Matt S Trout said,"as" is only used by DBIC itself,but used to form the SQL.But I have a solution if you use MySQL as DB server.
The tip is that you can use "order by (num)" in MySQL,for instance:
"SELECT stu_id,SUM(score) FROM stu_score group by stu_id order by 2 desc"
It does work~~
So you can use DBIC like this:
my $st = $schema->resultset('StuScore')->search(
{},
{
select => ['stu_id',{ sum => 'score' }],
as => ['stu','total_score'],
group_by => ['stu_id'],
order_by => ['2 desc'],
}
);
Remember,it works in MySQL only.(or in other words,I don't know if it could work in other DB servers).
Enjoy it^^
¶Ò壬Touya
Adways Co.Ltd
Telephone: (86-21)63410128-212
FAX: (86-21)63410208
Email: dong.yi at adways.net
http://dev.adways.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060322/d051e1fe/attachment.htm
More information about the Dbix-class
mailing list