子查询错误

时间:2015-11-23 10:17:58

标签: mysql sql subquery

我无法在下面的sql子查询中找到错误。我想将PublisherWise ImgCount作为我的输出。请指导我错误的地方。 TIA。

SELECT pubinfo.mf_pu_id,pubinfo.mf_pu_name, lang.mf_li_name, COUNT(innQ1.mf_cr_fileid) AS Imgcount 
FROM  mf_publication_info AS pubinfo 
LEFT JOIN 
    (SELECT mf_cr_fileid,mf_cr_masid,mf_cr_pubid, innQ.`mf_mi_publisheddate`                                          
     FROM mf_compare_results  
     WHERE mf_cr_enginedecision='p'AND mf_cr_userdecision IN('M',' M',' EM','EM')
     INNER JOIN 
         (SELECT mf_mi_id,mf_mi_publisheddate 
          FROM mf_media_info  
          WHERE mf_mi_publisheddate BETWEEN '2015-07-27' AND 
              '2015-07-31' AND `mf_mi_processid`=16
         ) AS innQ
     ) AS innQ1  
      ON innQ1.mf_cr_fileid=innQ.mf_mi_id
      ON pubinfo.mf_pu_id=innQ1.mf_cr_pubid
      INNER JOIN mf_language_info lang
          ON pubinfo.mf_pu_langid = lang.mf_li_id
          GROUP BY pubinfo.mf_pu_name ORDER BY pubinfo.mf_pu_name

1 个答案:

答案 0 :(得分:0)

对以下两种解释持开放态度(我认为),如果我错了,请你纠正我。

示例1:

SELECT x
FROM table 1
    LEFT JOIN (sub 1) alias ON x=x
    INNER JOIN (sub 2) alias ON x=x
    INNER JOIN table 2 ON x=x
GROUP BY x
ORDER BY x

示例2:

SELECT x
FROM table 1
    LEFT JOIN (
        (sub 1) alias
        INNER JOIN
        (sub 2) alias ON x=x
    ) alias ON x=x
    INNER JOIN table 2 ON x=x
GROUP BY x
ORDER BY x

如果它是第二个(这对我来说是有意义的),那么你需要第一个子查询的别名和第一个左连接的开放括号和第一个内部连接子查询的ON条件。

请写一下,因为我有一个非常简化的版本,你应该用这种方式更有意义。