2013-11-07 10:42:29 4499次浏览 1条回答 0 悬赏 10 金钱

select s.Name,  SUM(o.Count)/COUNT(o.ShipID) as ave
from tbl_order as o
LEFT JOIN tbl_ship as s ON s.ID = o.ShipID 

GROUP BY o.ShipID 


上面这个查询语句 我走model的search()方法可以用 一些方法实现,但是 as ave 这个 ave 我怎么在页面调用?

  • 回答于 2013-11-07 11:57 举报

    $conn = Yii::app->db();
    $sql = '

    select s.

    Name
    

    , SUM(o.Count)/COUNT(o.ShipID) as ave
    from tbl_order as o
    LEFT JOIN tbl_ship as s ON s.ID = o.ShipID

    GROUP BY o.ShipID';

    $qRecord = $conn->execute($sql);

    这里把qRecord抛到前台就可以了。
    注:没有测试,如果不对,下午测试之后再发一份!

    1 条回复
    回复于 2013-11-07 13:47 回复

    不要DB 我这SQL不复杂 直接走 model的search()就行,
    $criteria=new CDbCriteria;

    if(Yii::app()->getController()->getAction()->id == "FillingT" ){ 
    $criteria->select = ' s.Name as ShipID,ROUND(SUM(t.Count)/COUNT(t.ShipID),2) as ave  ';
    $criteria->join = 'LEFT JOIN tbl_ship as s ON s.ID = t.ShipID  '; 
        $criteria->group = 't.ShipID'; 
    }
    

    问题解决了 在这个model新建属性 ave 就可以了.

您需要登录后才可以回答。登录 | 立即注册
ww198787
助理

ww198787

注册时间:2013-10-18
最后登录:2013-12-30
在线时长:10小时10分
  • 粉丝0
  • 金钱0
  • 威望0
  • 积分100

热门问题