Mysql查询未知行为

时间:2017-01-06 09:35:20

标签: mysql sql wordpress

我有以下查询,我正在为wordpress网站工作:

Select
    posts_tender.ID AS tender_ID,
    tender_meta_user_ministry_tbl.meta_value,
    CONCAT('<a style="font-weight: bold;font-size: 15px;" href="'
          ,posts_tender.guid
          ,'" target="_blank">المزيد...</a>') AS tender_title_with_link_to_post,
    posts_tender.post_status AS tender_post_status,
    DATE_FORMAT(STR_TO_DATE(tender_meta_tender_date_tbl.meta_value , '%Y-%m-%dT%H:%i'), '%d/%m/%Y') AS tender_meta_tender_date,
    posts_tender.post_title AS tender_meta_tender_subject,
    tender_taxonomy_language_tbl.name AS tender_taxonomy_language,
    tender_taxonomy_tendercategory_tbl.name AS tender_taxonomy_tendercategory,
    tender_meta_tender_status_tbl.meta_value AS tender_meta_tender_status
FROM wp_posts AS posts_tender
LEFT OUTER JOIN 
        (SELECT tender_meta_tender_date_tbl_posts.ID as id,
                meta_value, 
                meta_key  
         FROM wp_postmeta AS tender_meta_tender_date_tbl_postmeta 
         INNER JOIN wp_posts AS tender_meta_tender_date_tbl_posts  
           ON tender_meta_tender_date_tbl_postmeta.post_id = tender_meta_tender_date_tbl_posts.ID   
           AND tender_meta_tender_date_tbl_posts.post_type = 'tender'
        ) AS tender_meta_tender_date_tbl
  ON tender_meta_tender_date_tbl.meta_key = 'tender_date' 
  AND tender_meta_tender_date_tbl.id = posts_tender.ID
LEFT OUTER JOIN 
        (SELECT tender_meta_user_ministry_tbl_posts.ID as id, 
                meta_value, 
                meta_key  
         FROM wp_postmeta AS tender_meta_user_ministry_tbl_postmeta 
         INNER JOIN wp_posts AS tender_meta_user_ministry_tbl_posts   
           ON tender_meta_user_ministry_tbl_postmeta.post_id = tender_meta_user_ministry_tbl_posts.ID   
           AND tender_meta_user_ministry_tbl_posts.post_type = 'tender'
        ) AS tender_meta_user_ministry_tbl
  ON tender_meta_user_ministry_tbl.meta_key = 'user_ministry' 
  AND tender_meta_user_ministry_tbl.id = posts_tender.ID
LEFT OUTER JOIN 
        (SELECT name, 
                object_id as id 
         FROM wp_terms AS tender_taxonomy_language_tbl_terms 
         INNER JOIN wp_term_taxonomy AS tender_taxonomy_language_tbl_termtaxonomy 
           ON tender_taxonomy_language_tbl_termtaxonomy.term_id = tender_taxonomy_language_tbl_terms.term_id  
           AND tender_taxonomy_language_tbl_termtaxonomy.taxonomy = 'language' 
         INNER JOIN wp_term_relationships AS rel_tender_taxonomy_language_tbl  
           ON tender_taxonomy_language_tbl_termtaxonomy.term_taxonomy_id = rel_tender_taxonomy_language_tbl.term_taxonomy_id
        ) AS tender_taxonomy_language_tbl
  ON tender_taxonomy_language_tbl.ID = posts_tender.id
LEFT OUTER JOIN
        (SELECT name, 
                object_id as id,
                tender_taxonomy_tendercategory_tbl_terms.term_id AS tender_category_id 
         FROM wp_terms AS tender_taxonomy_tendercategory_tbl_terms 
         INNER JOIN wp_term_taxonomy AS tender_taxonomy_tendercategory_tbl_termtaxonomy 
           ON tender_taxonomy_tendercategory_tbl_termtaxonomy.term_id = tender_taxonomy_tendercategory_tbl_terms.term_id  
           AND tender_taxonomy_tendercategory_tbl_termtaxonomy.taxonomy = 'tendercategory' 
         INNER JOIN wp_term_relationships AS rel_tender_taxonomy_tendercategory_tbl  
            ON tender_taxonomy_tendercategory_tbl_termtaxonomy.term_taxonomy_id = rel_tender_taxonomy_tendercategory_tbl.term_taxonomy_id
        ) AS tender_taxonomy_tendercategory_tbl
  ON tender_taxonomy_tendercategory_tbl.ID = posts_tender.id
LEFT OUTER JOIN 
        (SELECT tender_meta_tender_status_tbl_posts.ID as id, 
                meta_value,
                meta_key  
         FROM wp_postmeta AS tender_meta_tender_status_tbl_postmeta  
         INNER JOIN wp_posts AS tender_meta_tender_status_tbl_posts   
           ON tender_meta_tender_status_tbl_postmeta.post_id = tender_meta_tender_status_tbl_posts.ID   
           AND tender_meta_tender_status_tbl_posts.post_type = 'tender'
        ) AS tender_meta_tender_status_tbl
  ON tender_meta_tender_status_tbl.meta_key = 'tender_status' 
  AND tender_meta_tender_status_tbl.id = posts_tender.ID 
where  1=1
AND posts_tender.post_type = 'tender'
And posts_tender.post_status = 'publish'
And tender_taxonomy_language_tbl.name = 'العربية'
And (tender_meta_tender_status_tbl.meta_value is NULL 
  OR tender_meta_tender_status_tbl.meta_value = 0)
And SUBSTRING_INDEX(
        SUBSTRING_INDEX(
            tender_meta_user_ministry_tbl.meta_value,
            '\"', 
            -2), 
        '\"', 
        1) = Case 
               When (1103 = 0 Or 1103 = '' Or 1103= null Or 1103= 'null')
                 then 0
               else 1103 
             End

并且查询在我的本地数据库上正常工作,但在实时环境中导入数据库后,查询没有返回任何数据。

解决问题后,如果我在查询中添加了以下where条件,则会返回一条记录:

  

和posts_tender.ID = 14261

有没有人知道为什么会这样?

0 个答案:

没有答案