2012-05-29 43 views
0

這是我正在嘗試做的。根據特定條件從表中獲取數值計數的總和,並將此返回值作爲父級選擇的列,但是我無法讓我的頭部圍繞最佳(即可行)方法來執行此操作。我試過MySql得到子選擇的總和作爲父列的選擇

SELECT 
sum(count(distinct(frsrvdate))) 
FROM webusers.tblQAuditClaims qac inner join webusers.tblQAuditDetails qad using (claimId) 
where qac.auditdate between '2012-01-01' and '2012-03-31' 
and IsResubmitted = 0 
and qad.errorflag = 0 
and qac.errorflag = 0 
which throws an invalid group function. 

開始認爲我正在用我的方法去掉這個錯誤的兔子洞。對我失蹤的任何建議?

我已經將它縮減到了子選擇部分,但仍然遇到了如何獲得總數的問題。

+1

你可以把你的架構和高達在http://sqlfiddle.com一些示例數據,然後編輯你的問題,以顯示您所需的輸出將是什麼樣子? – eggyal

+0

這是否是說明問題的最小數量的SQL?那裏有修辭問題......它不是**。請參閱[SSCCE](http://sscce.org),然後將代碼修剪至最低限度 – Bohemian

回答

0

在第一個查詢中你有一個額外的)。

更正一個 -

sum(SELECT count(distinct(FrSrvDate)) 
    FROM webusers.tblQAuditClaims qac Left Join webusers.tblQAuditDetails qad using  (claimId) 
    where qac.auditdate between '2012-01-01' and '2012-03-31' 
    and IsResubmitted = 0 
    and qad.errorflag = 0 
    group by tracenumber)