0

select es.* from g5ch3_empstatus_objectsas esinner join(select statuscreator,statuscreatorid,max(created)as maxcreated, usstatus from g5ch3_empstatus_objectswhere statuscreator='user->name' group by statuscreator )s on es.statuscreator=s.statuscreator and es.created= s.maxcreated

如何在使用 joomla2.5 的 Joomla 模型类中编写此查询

我已经尝试过这种方式,但我得到了空的结果集:

$query = $db->getQuery(true);    
$subquery = $db->getQuery(true);
$subquery->select('max(created) as maxcreated')
-> from ('#_empstatus_objects');
$query->select(
        'es.id as id,' .
        'es.statuscreator,' .
        'es.statuscreatorid,' .
        'es.created,' .
        'es.ustatus'
);
$query->from ('#__empstatus_objects as es'.$subquery.$where)
-> group('statuscreator');

$superadmin = $this->access_superuser($user->id);
if(!$superadmin){
    $query->where ('statuscreatorid='.$user->id);    
}
4

1 回答 1

0

转到http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5并查看“从多个表中选择记录”部分。

于 2013-07-15T23:29:58.167 回答