加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Cakephp DISTINCT

发布时间:2020-12-13 18:08:57 所属栏目:PHP教程 来源:网络整理
导读:如何使用DISTINCT为total_time_driven_at_this_trip获取具有最高值的唯一用户ID,还从另一个基于user_id的属于关系的表中提取user_name? 我试过这个…… $this-set('tripNsws',$this-TripNsw-find('all',array('limit' = 20,'fields' = array('DISTINCT(Trip
如何使用DISTINCT为total_time_driven_at_this_trip获取具有最高值的唯一用户ID,还从另一个基于user_id的属于关系的表中提取user_name?

我试过这个……

$this->set('tripNsws',$this->TripNsw->find('all',array('limit' => 20,'fields' => array('DISTINCT(TripNsw.user_id)','TripNsw.total_time_driven_at_this_trip'),'group' => array('TripNsw.user_id'),'order' => array('TripNsw.total_time_driven_at_this_trip desc'))));

但它不起作用.

我想你需要得到以下……

SELECT DISTINCT(user_id),`total_time_driven_at_this_trip` FROM `trip_nsws` order by `total_time_driven_at_this_trip` desc
// see below url

    http://book.cakephp.org/1.3/view/1018/find


 array(
    'conditions' => array('Model.field' => $thisValue),//array of conditions
    'recursive' => 1,//int
    'fields' => array('Model.field1','DISTINCT Model.field2'),//array of field names
    'order' => array('Model.created','Model.field3 DESC'),//string or array defining order
    'group' => array('Model.field'),//fields to GROUP BY
    'limit' => n,//int
    'page' => n,//int
    'offset'=>n,//int
    'callbacks' => true //other possible values are false,'before','after'
)



// or try this



function some_function() {

    $total = $this->Article->find('count');

    $pending = $this->Article->find('count',array('conditions' => array('Article.status' => 'pending')));

    $authors = $this->Article->User->find('count');

    $publishedAuthors = $this->Article->find('count',array(
    'fields' => 'DISTINCT Article.user_id','conditions' => array('Article.status !=' => 'pending')
    ));

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读