如何將此查詢轉換爲symfony 2準則查詢生成器?學說查詢生成器 - 嵌套查詢
SELECT artist_id,日期,餘額,類型FROM交易爲T1 WHERE 日期=(SELECT MAX(日期)FROM交易WHERE artist_id = t1.artist_id與在 狀態( '部分', '未決', '扣除', '接受'),然後鍵入NOT LIKE '支付')GROUP BY artist_id ORDER BY artist_id
我試過如下:
$qb = $this->getEntityManager()->createQueryBuilder()
->select('t.balance','a.id','t.date')
->from('TestMainBundle:Transaction','t')
->Join('t.artist','a')
->where("t.status in ('partial','pending','deducted','accepted')")
->andWhere("t.type NOT LIKE 'payment'")
->groupBy('a.id')
->orderBy('a.id');
return $qb->getQuery()->getResult();
但我堅持包含max(date)的條件。對此非常感謝。
我想你需要類似這個[問題](https://stackoverflow.com/questions/11924164/subquery-in-doctrine2-notin-function) – squareCircle