我有一個存儲庫功能,我想使用CASE WHEN然後ELSE,但教義不允許在ELSE NULL。當然,我GOOGLE了,但我找不到答案如何避免它。主義CASE WHEN然後是NULL
public function countAverageOdd($user) {
return $this->getEntityManager()
->createQuery('
SELECT
avg(
CASE
WHEN p.homeAway = \'h\' AND p.moneyline IS NOT NULL THEN m.home
WHEN p.homeAway = \'d\' AND p.moneyline IS NOT NULL THEN m.draw
WHEN p.homeAway = \'e\' AND p.moneyline IS NOT NULL THEN m.away
WHEN p.homeAway = \'h\' AND p.spread IS NOT NULL THEN s.home
WHEN p.homeAway = \'e\' AND p.spread IS NOT NULL THEN s.away
WHEN p.homeAway = \'h\' AND p.total IS NOT NULL THEN t.over
WHEN p.homeAway = \'e\' AND p.total IS NOT NULL THEN t.under
ELSE NULL
END
)
FROM
AppBundle:Predictions p
LEFT JOIN p.moneyline m
LEFT JOIN p.spread s
LEFT JOIN p.total t
WHERE p.user = :user ')
->setParameter(":user", $user)
->setMaxResults(1)
->getSingleScalarResult();
}
錯誤:[語法錯誤] 0行,列900 :錯誤:意外 'NULL'
https://github.com/doctrine/doctrine2/issues/3160
doctrinebot評論了2013年5月22日
問題以分辨率「不會修復」關閉
請給我建議。
我可以在下個星期一嘗試它,我會發布結果。 – NTsvetkov
謝謝!它的工作原理! – NTsvetkov