1
我必須從表格中獲取每週報告,每個記錄的狀態如1表示爲開放狀態,2表示關閉狀態,所以我使用周作爲組的鍵和用於差異計數的使用情況(如開放,封閉,紅色等,但數據並不準確,因爲我想。 你會更好地支持下面提到的查詢。 每個響應都已撥出。有條件的計數MySQL
SELECT DISTINCT discussion_date,department,DAYNAME(discussion_date) AS DAY,CONCAT(YEAR(discussion_date),'/',WEEK(discussion_date)) AS week_name,YEAR(discussion_date) AS YEAR,CONCAT('WEEK -', WEEK(discussion_date)) AS week_no,COUNT(*) as total_queries,(CASE WHEN review_items.status = 1 AND due_date > curdate() THEN count(*) ELSE 0 END) as open,(CASE WHENreview_items.status = 2 THEN count(*) ELSE 0 END) as closed,(case when manager_closuredate > due_date THEN count(*) ELSE 0 END) as red,(CASE WHEN review_items.status = 3 THEN count(*) ELSE 0 END) as hold,(CASE WHEN review_items.status = 4 THEN count(*) ELSE 0 END) as discussion,DATE_ADD(discussion_date,INTERVAL(2 - DAYOFWEEK(discussion_date)) DAY) AS Week_start_date,DATE_ADD(discussion_date,INTERVAL(7 - DAYOFWEEK(discussion_date)) DAY) AS Week_end_date,DAYNAME(DATE_ADD(discussion_date,INTERVAL(2 - DAYOFWEEK(discussion_date)) DAY)) AS WeeK_Start_DAY FROM review_items
WHERE department = 'Development' AND discussion_date BETWEEN '2017-08-01' AND '2017-08-31'
GROUP BY week_name
ORDER BY YEAR (discussion_date) ASC,WEEK(discussion_date) ASC
是它的工作,謝謝@sagi。 –