2017-04-05 245 views
0

我的查詢語句在設置和預算時都返回null。MySQL多查詢返回空值查詢

但是,如果我刪除值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 
+0

嘗試enc用'()'丟失每個條件 – Swellar

+0

您錯過了'group by'子句 – Jens

+0

如果刪除'client = 11 AND',會發生什麼? – Bondt

回答

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

+0

謝謝!當它允許我時,我會標記爲正確 – David

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 
+0

沒有工作--MySQL返回了一個空的結果集 – David

+0

你能否請求驗證客戶端的列名?客戶端是你的整數列嗎? –