0

テーブルの列expから最大数を選択するにはどうすればよいですか。それが私のテーブルです:

id | name | views |
1|テスト|42|
2 | test1 | 89 |
3 | test2 | 4 |
4 | test3 | 35 |

ビューは他のビューの中で最も多いので、行ID 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);
4

1 に答える 1

2

試す...

$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

于 2012-09-12T17:21:48.400 に答える