我有一个仓库函数,我想使用CASE WHEN THEN ELSE,但是规则不允许在ELSE中使用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日发表评论
问题已关闭,解决方案为“with‘t Fix”
请给我一些建议。
https://stackoverflow.com/questions/44497483
复制相似问题