Baseado na documentação do Zend 1.12, usando o query builder:
Como eu seleciono duas tabelas apenas com vírgula sem joinInner
:
Exemplo:
SELECT TABELA1 FROM
(
BLABLABLA...
) A,
(SELECT TABELA2) B
Pra entender meu problema, esse é o código:
$selectRankQuery = $this->dbTable->select()
->setIntegrityCheck(false)
->from(array('opn' => 'olympic_players_niveis'),
array(
'opn.user_id',
'SUM(opn.points) as total_points'
));
if ($olympic_id != null) {
$selectRankQuery->where('opn.olympic_id = ? ', $olympic_id);
} else {
$selectRankQuery->joinInner(array('ol' => 'olympics'),
'opn.olympic_id = ol.ID and ol.active = 1',
array(
));
}
$selectRankQuery->group('opn.user_id');
$init = new Zend_Db_Expr("SELECT @rank := 0");
$select = $this->dbTable->select()
->setIntegrityCheck(false)
->from(array('rank_res' => $selectRankQuery),
array(
'rank_res.*',
new Zend_Db_Expr('@rank := @rank + 1 rank')
))
//o que eu uso aqui para ficar uma vírgula ????
->join(array('init' => $init));
$r = $select->assemble();
Só preciso iniciar a variável @rank := 0
no select;
Eu tentei isso, mas a query não mostrou o valor de ranking:
->from(array('rank_res' => $selectRankQuery, 'init' => $init)
;
Basicamente, esta deveria ser a saída:
SELECT
`rank_res`.*,
@rank:=@rank + 1 rank
FROM
(SELECT
`opn`.`user_id`, SUM(opn.points) AS `total_points`
FROM
`olympic_players_niveis` AS `opn`
WHERE
(opn.olympic_id = 9)
GROUP BY `opn`.`user_id`) AS `rank_res`,
(SELECT @rank:=0) AS `init`