本文介绍了Symfony2 + Doctrine + case语句:如何在DQL或其他语句中执行case语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在我的查询生成器 ...
I have to use case statements
into my query builder...
我的查询是这样的:
$query = $this->getEntityManager('V')->createQuery(
'SELECT V,
(CASE unit WHEN "DAY" THEN DATE_ADD( NOW() , INTERVAL start_date DAY )
WHEN "MONTH" THEN DATE_ADD( NOW() , INTERVAL start_date MONTH )
WHEN "YEAR" THEN DATE_ADD( NOW() , INTERVAL start_date YEAR )
END as startDate
)
FROM AppMyBundle:Entity V
WHERE 1=1
ORDER BY date ASC'
);
请注意,在MySQL中是正确的。
Note that it is correct in MySQL.
我不知道如何解决...
I don't know how to solve it...
如果你有另一个想法,请随时帮助我:)
If you have another idea, feel free to help me :)
任何想法?
推荐答案
$query = $this->getDoctrine()->getEntityManager()->getConnection()->prepare(
"SELECT V.id,
(CASE WHEN "DAY" THEN DATE_ADD( NOW() , INTERVAL start_date DAY )
WHEN "MONTH" THEN DATE_ADD( NOW() , INTERVAL start_date MONTH )
WHEN "YEAR" THEN DATE_ADD( NOW() , INTERVAL start_date YEAR )
END as startDate
)
FROM table_name V
WHERE V.id = :id
ORDER BY date ASC"
);
$query->bindValue('id', $id);
$query->execute();
$results = $query->fetchAll();
尝试这个我希望它为你工作
谢谢,
Ashok Chitroda
Try this one I hope it working for youThanks,Ashok Chitroda
这篇关于Symfony2 + Doctrine + case语句:如何在DQL或其他语句中执行case语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!