一个错误的子查询在几个条件下工作&别人失败了吗?

时间:2016-08-03 10:24:00

标签: mysql mariadb tokudb

以下两个查询完全相同,但国家/地区名称除外。在查询1中,它是“马来西亚”&在查询2中它是“印度”。

查询本身是错误的;因为我在第一个子查询中使用“ac.country”而我实际上需要使用“ass.country”,但我仍然在查询1中得到结果,而在查询2中我得到NULL。

有人可以解释为什么会这样。

查询1:

SELECT DATE(DAY) AS daycust,
            (SELECT SUM(Quantity) AS webss 
            FROM ACQ AS ass
            WHERE ass.day = ac.day 
            AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
            AND country =  'Malaysia') AS webss

FROM analytics_country AS ac

WHERE DAY BETWEEN  '2016-07-01' AND  '2016-08-02'
             AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
             AND country =  'Malaysia'

GROUP BY daycust
ORDER BY daycust

查询2:

SELECT DATE(DAY) AS daycust,
            (SELECT SUM(Quantity) AS webss 
            FROM ACQ AS ass
            WHERE ass.day = ac.day 
            AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
            AND country =  'India') AS webss

FROM analytics_country AS ac

WHERE DAY BETWEEN  '2016-07-01' AND  '2016-08-02'
             AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
             AND country =  'India'

GROUP BY daycust
ORDER BY daycust

注意:我还想补充说,不同版本的MySql的输出会有所不同。

In Server version: "5.5.30-tokudb-7.0.1-MariaDB-log" -> Both the queries work fine.

In Server version: "5.5.41-tokudb-7.5.5-MariaDB - MariaDB Server" -> Only Query 1 works fine.

0 个答案:

没有答案