2017-01-25 80 views
0

我想檢索每個顧問的待處理查詢計數和已完成查詢的計數,並在表格中顯示。什麼是SQL查詢來檢索這些數據?通過對SQL查詢進行分組檢索個人計數

SELECT CounsellorName, 
    (SELECT COUNT(Status) 
    FROM register WHERE Status='Pending') AS pending, 
    (SELECT COUNT(Status) FROM register WHERE Status='Completed') AS completed 
FROM register 
GROUP BY CounsellorName 

我目前使用這個,但它不檢索每個顧問的個人計數。

感謝您的支持!

回答

0

試試這個:

SELECT CounsellorName, 
    sum(Status='Pending') AS pending, 
    sum(Status='Completed') AS completed 
FROM register 
GROUP BY CounsellorName 

發現未決的數量和每counsellorName完成狀態。

+0

非常感謝!它的工作:) – Viduni

+0

@VUsh請標記接受的答案,如果它的工作。 – GurV