php – 内在的教义子查询

前端之家收集整理的这篇文章主要介绍了php – 内在的教义子查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 MySql中有功能查询
select t.won,e.etot,s.username,s.country,r.points,r.rank FROM sf_guard_user s 
INNER JOIN marks r ON r.user_id = s.id 
inner join (select t.user_id,count(t.user_id)as won from topper t group by t.user_id) t on t.user_id=s.id
inner join (select e.user_id,count(e.user_id)as etot from exams e group by e.user_id) e on e.user_id=s.id
ORDER BY r.rank asc

我在sfGuardUserTable类中写了原则代码

$q= $this->createQuery('u');

        $wq =$q->createSubquery()
         ->select('t.user_id,count(t.user_id) won')
         ->from('Topper t')
         ->groupBy('t.user_id');

        $dq = $q->createSubquery()
         ->select('e.user_id,count(e.user_id) etot')
         ->from('Exams d')
         ->groupBy('d.user_id');

        $q->select(' t1.won,e1.dtot,u.username,u.country,r.rank')
         ->innerJoin ('u.Marks r ON r.user_id = u.id')
         ->innerJoin ('u.('.$wq->getDql().') t1 on t1.user_id=u.id')
         ->innerJoin ('u.'.$dq->getDql().' e1 on e1.user_id=u.id')
         ->orderBy('r.rank asc');

        //echo $q->getsql();
        return $q;

它是给错误找不到类SELECT :(请帮助我,谢谢提前.

我试图直接执行我的自定义查询由Doctrine Row @R_404_194@选项及其工作:)
我喜欢在这里分享
$q = new Doctrine_Rawsql();
        $q->select('{t.won},{e.etot},{s.username},{s.country},{r.marks},{r.ranks}');
        $q->from('sf_Guard_User s INNER JOIN marks r ON r.user_id = s.id inner join (select t.id,t.user_id,count(t.user_id)as won from topper t group by t.user_id) t on t.user_id=s.id inner join (select d.id,d.user_id,count(e.user_id)as etot from exams e group by e.user_id) e on e.user_id=s.id ORDER BY r.rank asc');
        $q->addComponent('s','sfGuardUser s');
        $q->addComponent('r','s.Marks r');
        $q->addComponent('t','s.Topper t');
        $q->addComponent('e','s.Exams e');
        return $q;

为更多的帮助read it.

猜你在找的PHP相关文章