带有多个返回null的MySQL查询

时间:2017-04-05 10:09:55

标签: mysql

我的查询对于设置和预算都返回null。

但是,如果我删除值11之后的所有内容,则可以正常工作。

有谁知道最近发生了什么?

SELECT  SUM(setup_fee) AS setup, 
        SUM(budget) AS budget 
FROM gdn 
WHERE client = 11 
AND start_date BETWEEN 2017-03-26 AND 2017-04-30 
AND end_date BETWEEN 2017-03-26 AND 2017-04-30

2 个答案:

答案 0 :(得分:0)

尝试使用以下查询

    SELECT SUM(setup_fee) AS setup, SUM(budget) AS budget FROM gdn WHERE client = 
    11 AND ( start_date BETWEEN 2017-03-26 AND 2017-04-30) AND ( end_date BETWEEN 
    2017-03-26 AND 2017-04-30) group by client

答案 1 :(得分:0)

您的问题既不是分组的缺席,也不是围绕条件的括号,而是您必须引用这些日期值:

SELECT  SUM(setup_fee) AS setup, 
        SUM(budget) AS budget 
FROM    gdn 
WHERE   client = 11 
        AND start_date BETWEEN '2017-03-26' AND '2017-04-30'
        AND end_date BETWEEN '2017-03-26' AND '2017-04-30'

您可以看到已复制问题的简化版here