<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>
<DIV><FONT size=3>Dear all:</FONT></DIV>
<DIV><FONT size=3> I have got a problem when I use
DBIx::Class->resultset->search({},{order_by=>[...]})</FONT></DIV>
<DIV><FONT size=3></FONT> </DIV>
<DIV><FONT size=3>SQL in MySQL which works well:</FONT></DIV>
<DIV><FONT size=3>select name,sum(score) as total_score from stu_score group by
stu_id order by total_score desc</FONT></DIV>
<DIV><FONT size=3></FONT> </DIV>
<DIV><FONT size=3>I wanted to implement it using DBIC,but I found mistake
here.</FONT></DIV>
<DIV><FONT size=3></FONT> </DIV>
<DIV><FONT size=3>code:</FONT></DIV>
<DIV><FONT size=3>$schema->resultset('StuScore')->search(</FONT></DIV>
<DIV><FONT size=3> {},</FONT></DIV>
<DIV><FONT size=3> {</FONT></DIV>
<DIV><FONT size=3>
select=>['name',{'sum'=>'score'}],</FONT></DIV>
<DIV><FONT
size=3> as=>['name','total_score'],</FONT></DIV>
<DIV><FONT size=3> group_by=>['stu_id'],</FONT></DIV>
<DIV><FONT size=3> order_by=>['total_score
desc'],</FONT></DIV>
<DIV><FONT size=3> },</FONT></DIV>
<DIV><FONT size=3>);</FONT></DIV>
<DIV><FONT size=3></FONT> </DIV>
<DIV><FONT size=3>Error:</FONT></DIV>
<DIV><FONT color=#ff0000 size=3>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.</FONT></DIV>
<DIV><FONT color=#ff0000 size=3></FONT> </DIV>
<DIV><FONT color=#ff0000 size=3>Tracing SQL:</FONT></DIV>
<DIV><FONT color=#ff0000>
<DIV><FONT size=3>SELECT name,SUM( score ) FROM stu_score GROUP
BY stu_id ORDER BY total_score desc</FONT></DIV>
<DIV><FONT color=#000000 size=3></FONT> </DIV>
<DIV><FONT size=3>Why there is no 'as' in SQL?So that I cann't order by
total_score...</FONT></DIV>
<DIV><FONT size=3>How can I use order by in this case?</FONT></DIV>
<DIV><FONT size=3></FONT> </DIV>
<DIV><FONT size=3>Thank you all:)</FONT></DIV></FONT></DIV></FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>���壬Touya<BR>Adways Co.Ltd �����������������Ϻ�������˾<BR>Telephone:
(86-21)63410128-212<BR>FAX: (86-21)63410208<BR>Email: <A
href="mailto:dong.yi@adways.net">dong.yi@adways.net</A><BR>Address:�Ϻ��㶫·689�ź�֤ͨȯ����2810��<BR><A
href="http://dev.adways.net">http://dev.adways.net</A></FONT></DIV></BODY></HTML>