gpt4 book ai didi

mysql - 案例在 Doctrine 查询生成器 where 子句中不起作用

转载 作者:行者123 更新时间:2023-11-29 10:50:05 25 4
gpt4 key购买 nike

我在where子句中遇到mysql CASE问题,

 $rides_q1 = $em->getRepository('IRRideBundle:Ride');
$query = $rides_q1->createQueryBuilder('a')
->where('(CASE WHEN a.ephemeral = 1 THEN a.date_beginning < NOW() AND a.date_ending > NOW()ELSE a.ephemeral = 0 END) AND a.active = 1 AND a.status = 5')
->getQuery();
$ridesQuery = $query->execute();



**[Syntax Error] line 0, col 93: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '<'**

[2/2] QueryException: [Syntax Error] line 0, col 93: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '<' +
[1/2] QueryException: SELECT a FROM IR\RideBundle\Entity\Ride a WHERE (CASE WHEN ephemeral = 1 THEN date_beginning < NOW() AND date_ending > NOW()ELSE ephemeral = 0 END)

我想准备这个sql查询,它与phpmyadmin一起工作正常

SELECT * FROM ride WHERE (CASE WHEN ephemeral = 1 THEN date_beginning < NOW() AND date_ending > NOW()ELSE ephemeral = 0 END) AND active = 1 AND `status_id` = 5 ORDER BY `date_ending` DESC

最佳答案

WHERE 中的 CASE 表达式是错误的。您可以将其转换为正常的复合条件,例如

(CASE WHEN a.ephemeral = 1 THEN a.date_beginning < NOW() AND a.date_ending > NOW()ELSE a.ephemeral = 0 END)

SELECT * FROM ride
WHERE ((a.ephemeral = 1
and a.date_beginning < NOW()
AND a.date_ending > NOW())
OR a.ephemeral = 0)
AND a.active = 1
AND a.status = 5
ORDER BY `date_ending` DESC

关于mysql - 案例在 Doctrine 查询生成器 where 子句中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43890433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com