Właśnie znalezione, robi wrażenie:
//-----------------------------------------
// This is perhaps the most complicated query
// in all of IPB, sheesh
//-----------------------------------------
$this->DB->build( array(
'select' => "SUM(a.images) as aimages, SUM(a.comments) as acomments, SUM(a.mod_images) as amimages, SUM(a.mod_comments) as amcomments, a.member_id, a.id, a.description, ( COUNT(*) - SUM(a.public_album) ) as public_album," .
$this->DB->buildCast(
$this->DB->buildSubstring( "MAX(" .
$this->DB->buildConcat( array(
array( $this->DB->buildRight(
$this->DB->buildConcat( array( array( '0000000000', 'string' ), array( 'last_pic_date' ) ) ),
10 )
),
array( $this->DB->buildRight(
$this->DB->buildConcat( array( array( '0000000000', 'string' ), array( 'last_pic_id' ) ) ),
10 )
)
) )
. ")", 1, 10 )
, 'UNSIGNED' ) . ' as alast_pic_date,' .
$this->DB->buildCast(
$this->DB->buildSubstring( "MAX(" .
$this->DB->buildConcat( array(
array( $this->DB->buildRight(
$this->DB->buildConcat( array( array( '0000000000', 'string' ), array( 'last_pic_date' ) ) ),
10 )
),
array( $this->DB->buildRight(
$this->DB->buildConcat( array( array( '0000000000', 'string' ), array( 'last_pic_id' ) ) ),
10 )
)
) )
. ")", 11, 10 )
, 'UNSIGNED' ) . ' as alast_pic_id',
'from' => array( 'gallery_albums' => 'a' ),
'where' => "a.category_id={$cat['id']}" . $al_restrict,
'group' => 'a.member_id',
'order' => 'alast_pic_date DESC',
'add_join' => array(
array(
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id=a.member_id',
'type' => 'left',
)
)
) );