【问题标题】:Zend Framework: Select the greatest number from table columnsZend Framework:从表列中选择最大的数字
【发布时间】:2012-09-12 17:15:31
【问题描述】:

如何从表格列中选择最大的数字,exp。那是我的桌子:

id|名称|查看次数|
1|测试|42|
2|test1|89|
3|测试2|4|
4|test3|35|

我需要选择第 2 行的所有值,因为视图是其他视图中最大的数量?我试试这个,但不工作:

$q = $this->select()->from($this->_name, array(new Zend_Db_Expr('MAX(views)'), 'id', 'name'))->order('name DESC')->limit(1)->group('name');

return $this->fetchRow($q);

【问题讨论】:

    标签: zend-framework zend-db-table zend-db-select


    【解决方案1】:

    试试……

    $q = $this->select()
            ->from($this->_name, array('id', 'name'))
            ->order('views DESC')
            ->limit(1);
    return $this->fetchRow($q);
    

    提示:

    Apply ORDER BY views DESC, and then LIMIT 1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      相关资源
      最近更新 更多