[英]What's wrong with this case SQL query?
maybe you can help, I'm using this case query, and I'm trying to do mysql weighting with it.也许你可以帮忙,我正在使用这个案例查询,我正在尝试用它做 mysql 加权。 What's wrong with it?它出什么问题了?
SELECT *
FROM cronjob_reloaded
WHERE site IN ('site1.com', 'site2.com')
ORDER BY (CASE site
WHEN 'site1.com' THEN 0.2
WHEN 'site2.com' THEN 0.8 ) * RAND( ) DESC
LIMIT 0 , 30
MySQL said: Documentation MySQL 说:文档
1064 - You have an error in your SQL syntax; 1064 - 您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ') * RAND() DESC LIMIT 0, 30' at line 4检查与您的 MySQL 服务器版本相对应的手册,以获取在第 4 行的 ') * RAND() DESC LIMIT 0, 30' 附近使用的正确语法
Here is the right syntax of CASE这是 CASE 的正确语法
SELECT *
FROM cronjob_reloaded
WHERE site IN ('site1.com', 'site2.com' )
ORDER BY (
CASE
WHEN site = 'site1.com' THEN 0.2
WHEN site = 'site2.com' THEN 0.8
END
) * RAND( ) DESC
LIMIT 0 , 30
CASE must be closed with END: CASE 必须以 END 结束:
CASE site
WHEN 'site1.com'
THEN 0.2
WHEN 'site2.com'
THEN 0.8
END -- Added this END to your query's CASE
One possible issue is that you have not used END CASE.一个可能的问题是您没有使用 END CASE。
Change:改变:
CASE site
WHEN 'site1.com'
THEN 0.2
WHEN 'site2.com'
THEN 0.8
)
To:至:
CASE site
WHEN 'site1.com'
THEN 0.2
WHEN 'site2.com'
THEN 0.8
END CASE
Refer to: MySQL site参考: MySQL网站
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.