当changin WHERE to =而不是> =时,MySQL SUM查询不起作用

时间:2016-11-06 05:05:22

标签: php mysql

为什么这个查询总结来自不同表的不同值有效:

SELECT paymentMethodId, SUM(price) AS total FROM (
    SELECT paymentMethodId, price FROM flights WHERE status >= 5 
    UNION ALL
    SELECT paymentMethodId, price FROM cruises WHERE status >= 5 
    UNION ALL
    SELECT paymentMethodId, price FROM cars WHERE status >= 5 
    UNION ALL
    SELECT paymentMethodId, price FROM hotels WHERE status >= 5 
 ) alias GROUP BY paymentMethodId

和这个(仅在WHERE条件下更改)不会:

SELECT paymentMethodId, SUM(price) AS total FROM (
    SELECT paymentMethodId, price FROM flights WHERE status = 5 
    UNION ALL
    SELECT paymentMethodId, price FROM cruises WHERE status = 5 
    UNION ALL
    SELECT paymentMethodId, price FROM cars WHERE status = 5 
    UNION ALL
    SELECT paymentMethodId, price FROM hotels WHERE status = 5 
 ) alias GROUP BY paymentMethodId

我必须指出,只有在汽车桌上才有现有行。

0 个答案:

没有答案