开发者

How can make this sql query in Zend Syntax

i'm a new user of Zend Framework, and i have a problem with the Zend syntax for make this query:

SELECT i.*, k.id as id_key, GROUP_CONCAT(DISTINCT k.nome ORDER BY k.id SEPARATOR " ") as tag, GROUP_CONCAT(DISTINCT f.dimensioni ORDER BY f.id SEPARATOR " | ") as formati
FROM immagine i
LEFT JOIN immagine_has_formato fi ON fi.immagine_codice=i.codice
LEFT JOIN formato f ON f.id=fi.formato_id
LEFT JOIN keyword_has_immagine ki ON ki.immagine_codice=i.codice
LEFT JOIN keyword k ON k.id=ki.keyword_id
WHERE i.libro_codice = '06' AND i.codice IN (
SELECT ki.immagine_codice FROM keyword_has_immagine ki
INNER JOIN keyword k ON k.开发者_运维百科id=ki.keyword_id
WHERE lower(k.nome) = 'steam'
)
GROUP BY i.codice

There's any one that can help me? Thanks!..


For subquerys, you can use this example as a basis:

...
$subselect = $this->select()->setIntegrityCheck(false);
        $subselect->from(array('e'=>'feed_entries'),array('e.id'))
                   ->join(array('f'=>'feeds'),'e.feed_id =f.id','')
                   ->join(array('ec'=>'entries_categorias'),'ec.entry_id =e.id','')
                   ->join(array('c'=>'categorias'),'ec.categoria_id =c.id','')
                   ->where('e.imagem332x332 =?',1)
                   ->where('e.deleted =?',0)
                   ->group('e.id')
                           ->where('c.nome IN(?)',$categories)
                       ->having('COUNT(DISTINCT ec.id) =?',count($categories));

$select = $this->select()->where('id IN ?',$subselect)->order('date DESC')->limit(4);
return $this->fetchAll($select);
...

For group_concat, I've never tried, but this page have some examples in the commments

Also, take a look at the Zend Db Expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜