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
#1064 - You have an error in your SQL syntax; 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
Thanks in advance
In MySQL, use unsigned
or signed
instead of int
. I prefer cast()
to 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.)
Or, more simply, use silent conversion:
(SUBSTRING_INDEX(m2.meta_value, '-', -1) + 0) as _rank
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.