[Dbix-class] DBIC 'order_by'
Touya
dong.yi at adways.net
Wed Mar 8 02:05:02 CET 2006
Dear all:
I have got a problem when I use DBIx::Class->resultset->search({},{order_by=>[...]})
SQL in MySQL which works well:
select name,sum(score) as total_score from stu_score group by stu_id order by total_score desc
I wanted to implement it using DBIC,but I found mistake here.
code:
$schema->resultset('StuScore')->search(
{},
{
select=>['name',{'sum'=>'score'}],
as=>['name','total_score'],
group_by=>['stu_id'],
order_by=>['total_score desc'],
},
);
Error:
DBD::mysql::st execute failed: Unknown column 'total_score' in 'order clause' at C:/Pe rl/site/lib/DBIx/Class/Storage/DBI.pm line 387.
Tracing SQL:
SELECT name,SUM( score ) FROM stu_score GROUP BY stu_id ORDER BY total_score desc
Why there is no 'as' in SQL?So that I cann't order by total_score...
How can I use order by in this case?
Thank you all:)
¶Ò壬Touya
Adways Co.Ltd °®µÂÍþÈí¼þ¿ª·¢£¨ÉϺ££©ÓÐÏÞ¹«Ë¾
Telephone: (86-21)63410128-212
FAX: (86-21)63410208
Email: dong.yi at adways.net
Address:ÉϺ£¹ã¶«Â·689ºÅº£Í¨Ö¤È¯´óÏÃ2810ÊÒ
http://dev.adways.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060308/136eb95d/attachment.htm
More information about the Dbix-class
mailing list