sql >> Database teknologi >  >> RDS >> Mysql

Flere underforespørgsler med zend-ramme

Prøv denne :

$psub=$this->db->select()
    ->setIntegrityCheck(false)
    ->from(array('p'=>'projecttouser'),array('count(p.u_id) as count'))
    //->join(array('i'=>'usermaster'),'p.u_id=i.id') // no need for this join
    ->where('usermaster.id=projecttouser.u_id');

$tsub=$this->db->select()
    ->setIntegrityCheck(false)
    ->from(array('t'=>'tasktotarget'),array('count(t.assigned_to) as tcount'))
    ->where('usermaster.id=tasktotarget.assigned_to');

$tasub=$this->db->select()
    ->setIntegrityCheck(false)
    ->from(array('ta'=>'tasktotarget'),array('count(ta.assigned_to) as tacount'))
    ->where('usermaster.id=tasktotarget.assigned_to AND tasktotarget.is_active = 1 ');

$sql=$this->db->select()
    ->setIntegrityCheck(false)
    ->from(array('u'=>'usermaster'), array('usermaster.*', 
            'proj' => new Zend_Db_Expr('(' . $psub . ')'),
            'target' => new Zend_Db_Expr('(' . $tsub . ')'),
            'active' => new Zend_Db_Expr('(' . $tasub . ')')))
    ->group('u.id')
    //->order($order_by . ' ' . $order)
    ->where('u.is_delete=false');

$resultSet = $this->fetchAll($sql);
return $resultSet;

Doc :http://framework.zend.com/manual /1.12/da/zend.db.select.html




  1. SQL Server 2008 Spatial:find et punkt i polygon

  2. Sådan staves året, når du formaterer en dato i Oracle

  3. Android-rum - Sådan rydder du sqlite_sequence for alle tabeller

  4. Betinget VED DUPLIKAT NØGLEOPDATERING (Opdater kun, hvis en bestemt betingelse er sand)