在查看控制器中的一些代码时,我发现查询中有一个奇怪的错误,基本上是在语句:
数据库内容:
柱:
category : client or case category
type : title or content
mainpage 1 or 0 (true or false)
价值观:
0;0;1
对应正常输出:
Case category;title;yes
电流输出:
Client;Content;No
phql公司:
SELECT content.id,
(CASE content WHEN content.category = 0 THEN 'Case category' WHEN content.category = 1 THEN 'Client' WHEN content.category = 2 THEN 'Case' WHEN content.category = 3 THEN 'Product' WHEN content.category = 4 THEN 'Product category' WHEN content.category = 5 THEN 'Team' WHEN content.category = 6 THEN 'Vacancy' WHEN content.category = 7 THEN 'Reference' WHEN content.category = 8 THEN 'Article' ELSE "Category not found" END) AS category
FROM Apps\Source\Models\MainContent AS content
GROUP BY content.id
事实上,所有“case-when”语句都返回错误的值,甚至tho(例如:数据库中的content.category=0,但它会获取“me”client event tho,因为它应该获取值1)
如果我把这个语句翻译成纯sql,只是为了测试它,它可以工作。。。
SELECT
content.id,
(CASE WHEN content.category = 0 THEN 'Case category' WHEN content.category = 1 THEN 'Client' WHEN content.category = 2 THEN 'Case' WHEN content.category = 3 THEN 'Product' WHEN content.category = 4 THEN 'Product category' WHEN content.category = 5 THEN 'Team' WHEN content.category = 6 THEN 'Vacancy' WHEN content.category = 7 THEN 'Reference' WHEN content.category = 8 THEN 'Article' ELSE "Category not found" END) AS category
FROM main_content AS content
GROUP BY content.id
输出:
Case category;title;yes
这是phql的怪事吗?
1条答案
按热度按时间brtdzjyr1#
这两个语句之间有一个区别(原始sql是按大小写搜索的,phql很简单):在phql中try
在这么多的情况下,创建一个“category”查找表并将其与“main\u content”连接不是更好吗?