我想在 Symfony 2.3 中使用 Doctrine 来运行这个查询.但似乎 Doctrine 不理解 CASE 语句.任何人都可以帮忙吗?提前谢谢你!
SELECT max(id) id, name发件人卡片WHERE 名称如 '%John%'按名称分组ORDER BY CASE 当名字像 'John %' THEN 0当名字像 'John%' THEN 1当名字像 '% John%' THEN 2其他 3完,名字
如果你正在使用 createQueryBuilder 那么你可以使用 like
<前>$query->addSelect("(CASE WHEN name like 'John %' THEN 0当名字像 'John%' THEN 1当名字像 '% John%' THEN 2ELSE 3 END) 作为隐藏命令");$query->orderBy('ORD', 'DESC');请注意,您必须具有隐藏".
您也可以使用学说本机查询.
I want to run this query by using Doctrine in Symfony 2.3. But it seems like Doctrine does not understand CASE statement. Can anyone help? Thank you in advance!
SELECT max(id) id, name
FROM cards
WHERE name like '%John%'
GROUP BY name
ORDER BY CASE WHEN name like 'John %' THEN 0
WHEN name like 'John%' THEN 1
WHEN name like '% John%' THEN 2
ELSE 3
END, name
If you are using createQueryBuilder then you can use like
$query->addSelect("(CASE WHEN name like 'John %' THEN 0 WHEN name like 'John%' THEN 1 WHEN name like '% John%' THEN 2 ELSE 3 END) AS HIDDEN ORD "); $query->orderBy('ORD', 'DESC');
Note that you must have "HIDDEN".
You can do with doctrine native query as well.
这篇关于如何在 Doctrine2 (Symfony2) 中按案例排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!