[英]MySQL Query is not working in 5.6
SELECT
p.ID, p.post_name as _slug,
p.post_title as _title,
p.post_modified as _updated,
m1.meta_value as _symbol,
CONVERT(SUBSTRING_INDEX(m2.meta_value,'-',-1), INTEGER) as _rank
FROM wp_posts AS p
LEFT JOIN wp_postmeta m1 ON p.id = m1.post_id AND m1.meta_key = '_cc_symbol'
LEFT JOIN wp_postmeta m2 ON p.id = m2.post_id AND m2.meta_key = '_cc_rank'
where
p.post_type='cryptocurrency' ORDER by p.ID asc LIMIT 1 OFFSET 0
This query is not working in MySQL Software version: 5.6.35-81.0此查询不适用于 MySQL 软件版本:5.6.35-81.0
#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 'INTEGER) as _rank, FROM wp_posts AS p LEFT JOIN wp_postmeta m1 ON p.id = m1.post' at line 1
检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“整数”附近使用的正确语法作为 _rank, FROM wp_posts AS p LEFT JOIN wp_postmeta m1 ON p.id = m1.post'
Thanks in advance提前致谢
In MySQL, use unsigned
or signed
instead of int
.在 MySQL 中,使用
unsigned
或signed
而不是int
。 I prefer cast()
to convert()
:我更喜欢
cast()
到convert()
:
CAST(SUBSTRING_INDEX(m2.meta_value, '-', -1) as unsigned) as _rank
(In older versions of MySQL, convert()
only converted between character sets, not types.) (在旧版本的 MySQL 中,
convert()
只在字符集之间转换,而不是在类型之间转换。)
Or, more simply, use silent conversion:或者,更简单地说,使用静默转换:
(SUBSTRING_INDEX(m2.meta_value, '-', -1) + 0) as _rank
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.