需要帮助识别第20行的语法错误

时间:2019-02-04 18:27:04

标签: mysql sql

db Fiddle

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本以使用正确的语法   在'DELETE FROM wp_postmeta WHERE post_id IN(在(         在第20行上选择pm.post”

-- Deleting all duplicate products in wp_posts table

DELETE FROM
wp_posts WHERE ID IN ( SELECT ID FROM
(
select ID,post_title,post_type,meta_value from 
(SELECT wp_postmeta.ID,post_title,post_type ,meta_value,
row_number()over(partition by post_title order by wp_postmeta.meta_value) rn                           
FROM   wp_postmeta 
JOIN wp_posts ON wp_postmeta.post_id = wp_posts.id 
WHERE  wp_posts.post_type = 'Product' 
  AND wp_postmeta.meta_key = '_regular_price' 

) t where t.rn <> 1
) AS aliasx
)

-- Deleting all corresponding wp_postmeta.post_ids that don't have a match in wp_posts.id after the duplicate deletion above

DELETE FROM wp_postmeta WHERE post_id IN (select post_id from (
  SELECT pm.post_id 
  FROM
    wp_postmeta pm
    LEFT JOIN 
    wp_posts p
    ON p.id = pm.post_id
  WHERE
    p.id IS NULL

) AS aliasy )

在MYPHPAdmin中,我得到了:

  

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(partition by post_title order by wp_postmeta.meta_value) rn ' at line 5

在在线验证器https://www.eversql.com/sql-syntax-check-validator/中 我明白了:

  

您的SQL语法有错误;似乎错误在周围:'(   在第21行按post_title顺序按'进行分区

似乎有很多不同的错误,具体取决于我在哪里运行查询。

0 个答案:

没有答案