早上好,mysql 查询显示已完成日期字段和总行数的案例,我想根据总案例计算这个,但不确定我是否可以在一个查询中完成所有这些。例如当前查询输出
Aug Sep Nov Total
10 20 20 50
那是的代码
SELECT * from(
Select Count(b.CaseID) As TotDB
from tblcontacts a
Inner Join tblcases b
On a.ContactID = b.ContactAssignedTo)a
CROSS JOIN
(Select
Sum(Month(b.StatusSubmittedDate) = 8) As Aug,
Sum(Month(b.StatusSubmittedDate) = 9) As Sep,
Sum(Month(b.StatusSubmittedDate) = 10) As Oct,
Count(b.CaseID) As Total,
ROUND (100*Count(b.CaseID)/Count(b.CaseID),2) As Conversion
From
tblcontacts a Inner Join
tblcases b On a.ContactID = b.ContactAssignedTo
Where
b.StatusSubmittedDate > '2012 - 01 - 01'
Group By
a.ContactFullName With Rollup
Having
Sum(b.CaseCommission) > 0.01)b
我需要它的输出如下,所以我在上面添加了 TotDB 行,看看是否有帮助,但没有。我需要知道的是,我能否在此查询中有一个列绕过 where/have 子句来显示所有记录
Aug Sep Nov Tot TotDB %Converted
10 20 20 50 100 50%
谢谢