使用DataStudio时如何解决MariaDB中的语法错误

 收藏

我正在Data Studio中进行个性化查询,该查询最初是在mysql中进行的,但是当我使用结果的字段之一时,遇到了下一个错误。

SQL语句错误:SQL语法错误;检查与您的MariaDB服务器版本相对应的手册以在第34行的'> ='20200301'AND <='20200331')'附近使用正确的语法

这是查询,错误为pm.meta_value的字段与pm.meta_key相关:

SELECT
p.ID as ID,
p.post_title,
pm.meta_value,
entidad.name,
CASE WHEN tv.URL != ''
            THEN 'SI'
            ELSE 'NO'
END,
t.name,
tv.URL,
p.post_date
FROM wp_posts p
  LEFT JOIN wp_postmeta pm on p.ID = pm.post_id
  LEFT JOIN wp_term_relationships rs ON p.ID=rs.object_id
  LEFT JOIN wp_term_taxonomy tt ON rs.term_taxonomy_id = tt.term_taxonomy_id
  INNER JOIN wp_terms AS t ON tt.term_id = t.term_id
  LEFT JOIN  (select p.ID, pm.meta_value as URL FROM wp_posts p
            LEFT JOIN wp_postmeta pm on p.ID = pm.post_id
            where pm.meta_key in ('test')
            and pm.meta_value != ''
            ) as tv on p.ID = tv.ID
  INNER JOIN (select p.ID, t.name name, tt.taxonomy taxonomy FROM wp_posts p
              LEFT JOIN wp_term_relationships rs ON p.ID=rs.object_id
  LEFT JOIN wp_term_taxonomy tt ON rs.term_taxonomy_id = tt.term_taxonomy_id
              INNER JOIN wp_terms AS t ON tt.term_id = t.term_id
            ) as entidad on p.ID = entidad.ID
WHERE p.post_type ='test1'
  AND p.post_status =  'test2'
  AND pm.meta_key = 'test3'
  AND entidad.taxonomy = 'test4'
  AND (tt.term_id = 15 OR
       tt.term_id = 174 OR 
       tt.term_id = 1960);
回复