我想問我的MySQL查詢是否有什麼問題(並且可能要求提供關於如何更好地執行此操作的建議)?我試圖在5天的範圍內生成每日報告......問題是它不顯示確切的數據,它填滿了沒有數據的日子。MySQL查詢錯誤...它不顯示確切的數據值
這是下面的MySQL查詢例子中: 在我的數據庫,週一,週三和週四與DATAS ..但如果我將運行使用此查詢報告,週二將有一個現成的它在我的數據庫中實際上沒有的數據。雖然IT,NonIt和合計表計數是正確的。我在計算僅在天中的數據時出錯。請幫助我...我不知道錯誤在哪裏。
爲了更好地解釋我的意思,這裏是我的查詢的輸出結果的截圖: http://www.fileden.com/files/2011/7/27/3174077//daily.JPG
SELECT a.specialist_partner_ID, ss.first_name as SS, ssa.first_name as SSA
,count(CASE WHEN a.receivedDate BETWEEN '2011-09-5' AND '2011-09-9'
THEN a.job_order_number ELSE null END) As MON
,count(CASE WHEN a.receivedDate BETWEEN date_add('2011-09-5', INTERVAL 1 DAY)
AND DATE_ADD('2011-09-9', INTERVAL 1 DAY) THEN a.job_order_number ELSE null END) As TUE
,count(CASE WHEN a.receivedDate BETWEEN date_add('2011-09-5', INTERVAL 2 DAY)
AND DATE_ADD('2011-09-9', INTERVAL 2 DAY) THEN a.job_order_number ELSE null END) As WED
,count(CASE WHEN a.receivedDate BETWEEN date_add('2011-09-5', INTERVAL 3 DAY)
AND DATE_ADD('2011-09-9', INTERVAL 3 DAY) THEN a.job_order_number ELSE null END) As THU
,count(CASE WHEN a.receivedDate BETWEEN date_add('2011-09-5', INTERVAL 4 DAY)
AND DATE_ADD('2011-09-9', INTERVAL 4 DAY) THEN a.job_order_number ELSE null END) As FRI
,count(case WHEN (a.receivedDate between '2011-09-5 00:00:00' and '2011-09-9 23:59:59'
and jo.job_order_type LIKE 'IT') then a.job_order_number else null end) as IT
,count(case WHEN (a.receivedDate between '2011-09-5 00:00:00' and '2011-09-9 23:59:59'
and jo.job_order_type LIKE 'Non-IT') then a.job_order_number else null end) as NonIT
,count(a.job_order_number) As Total FROM jo_partner a
left join specialist_partner sp on a.specialist_Partner_ID = sp.specialistPartnerID
left join staffing_specialist_asst ssa on sp.SSA_ID = ssa.SSA_ID
left join staffing_specialist ss on sp.SS_ID = ss.SS_ID
left join job_order jo on a.job_order_number = jo.job_order_number
left join candidate_jo cjo on a.JO_partner_ID= cjo.jo_partner_ID
left join candidate can on cjo.candidate_jo_ID= can.candidate_ID
WHERE a.receivedDate BETWEEN '2011-09-5 00:00:00' AND '2011-09-9 23:59:59'
GROUP BY a.specialist_partner_ID
你可以舉一些你的數據的例子嗎?在不知道數據是什麼樣的情況下調試您提供的查詢太困難了。 – invertedSpear
嘗試在日期中使用「2011-09-05 00:00:00」,而不是「2011-09-5 00:00:00」。 –
@invertedSpear感謝您的評論。示例結果在附上爵士的鏈接中。 –