如何使用DISTINCT
獲取具有最高值的唯一用戶ID爲total_time_driven_at_this_trip
,並且還從另一個基於user_id
屬於關係的表中獲取user_name
?Cakephp DISTINCT
我想這...
$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
我不認爲你的回答是有關的問題 - 在所有 – mark